4 #include "parse-options.h"
6 static const char * const git_symbolic_ref_usage
[] = {
7 N_("git symbolic-ref [options] name [ref]"),
13 static void check_symref(const char *HEAD
, int quiet
)
15 unsigned char sha1
[20];
17 const char *refname
= resolve_ref_unsafe(HEAD
, sha1
, 0, &flag
);
20 die("No such ref: %s", HEAD
);
21 else if (!(flag
& REF_ISSYMREF
)) {
23 die("ref %s is not a symbolic ref", HEAD
);
28 refname
= shorten_unambiguous_ref(refname
, 0);
32 int cmd_symbolic_ref(int argc
, const char **argv
, const char *prefix
)
35 const char *msg
= NULL
;
36 struct option options
[] = {
38 N_("suppress error message for non-symbolic (detached) refs")),
39 OPT_BOOL(0, "short", &shorten
, N_("shorten ref output")),
40 OPT_STRING('m', NULL
, &msg
, N_("reason"), N_("reason of the update")),
44 git_config(git_default_config
, NULL
);
45 argc
= parse_options(argc
, argv
, prefix
, options
,
46 git_symbolic_ref_usage
, 0);
48 die("Refusing to perform update with empty message");
51 check_symref(argv
[0], quiet
);
54 if (!strcmp(argv
[0], "HEAD") &&
55 prefixcmp(argv
[1], "refs/"))
56 die("Refusing to point HEAD outside of refs/");
57 create_symref(argv
[0], argv
[1], msg
);
60 usage_with_options(git_symbolic_ref_usage
, options
);