2006-08-03 23:24:38 +08:00
|
|
|
#include "builtin.h"
|
2005-10-01 05:26:57 +08:00
|
|
|
#include "cache.h"
|
2006-09-21 13:02:01 +08:00
|
|
|
#include "refs.h"
|
2007-10-08 05:18:23 +08:00
|
|
|
#include "parse-options.h"
|
2005-10-01 05:26:57 +08:00
|
|
|
|
2007-10-08 05:18:23 +08:00
|
|
|
static const char * const git_symbolic_ref_usage[] = {
|
2008-07-13 21:36:15 +08:00
|
|
|
"git symbolic-ref [options] name [ref]",
|
2007-10-08 05:18:23 +08:00
|
|
|
NULL
|
|
|
|
};
|
2005-10-01 05:26:57 +08:00
|
|
|
|
2007-01-16 05:56:05 +08:00
|
|
|
static void check_symref(const char *HEAD, int quiet)
|
2005-10-01 05:26:57 +08:00
|
|
|
{
|
|
|
|
unsigned char sha1[20];
|
2006-09-21 13:02:01 +08:00
|
|
|
int flag;
|
|
|
|
const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
|
2006-09-12 11:17:35 +08:00
|
|
|
|
|
|
|
if (!refs_heads_master)
|
2005-10-01 05:26:57 +08:00
|
|
|
die("No such ref: %s", HEAD);
|
2007-01-16 05:56:05 +08:00
|
|
|
else if (!(flag & REF_ISSYMREF)) {
|
|
|
|
if (!quiet)
|
|
|
|
die("ref %s is not a symbolic ref", HEAD);
|
|
|
|
else
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-09-12 11:17:35 +08:00
|
|
|
puts(refs_heads_master);
|
2005-10-01 05:26:57 +08:00
|
|
|
}
|
|
|
|
|
2006-08-03 23:24:38 +08:00
|
|
|
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
|
2005-10-01 05:26:57 +08:00
|
|
|
{
|
2007-01-16 05:56:05 +08:00
|
|
|
int quiet = 0;
|
2007-01-27 06:26:10 +08:00
|
|
|
const char *msg = NULL;
|
2007-10-08 05:18:23 +08:00
|
|
|
struct option options[] = {
|
|
|
|
OPT__QUIET(&quiet),
|
|
|
|
OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
|
|
|
|
OPT_END(),
|
|
|
|
};
|
2007-01-16 05:56:05 +08:00
|
|
|
|
2008-05-15 01:46:53 +08:00
|
|
|
git_config(git_default_config, NULL);
|
2007-10-08 05:18:23 +08:00
|
|
|
argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
|
|
|
|
if (msg &&!*msg)
|
|
|
|
die("Refusing to perform update with empty message");
|
2005-10-01 05:26:57 +08:00
|
|
|
switch (argc) {
|
2007-10-08 05:18:23 +08:00
|
|
|
case 1:
|
|
|
|
check_symref(argv[0], quiet);
|
2005-10-01 05:26:57 +08:00
|
|
|
break;
|
2007-10-08 05:18:23 +08:00
|
|
|
case 2:
|
|
|
|
create_symref(argv[0], argv[1], msg);
|
2005-10-01 05:26:57 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-10-08 05:18:23 +08:00
|
|
|
usage_with_options(git_symbolic_ref_usage, options);
|
2005-10-01 05:26:57 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|