5 #include "parse-options.h"
7 static const char * const git_symbolic_ref_usage
[] = {
8 N_("git symbolic-ref [<options>] <name> [<ref>]"),
9 N_("git symbolic-ref -d [-q] <name>"),
13 static int check_symref(const char *HEAD
, int quiet
, int shorten
, int print
)
16 const char *refname
= resolve_ref_unsafe(HEAD
, 0, NULL
, &flag
);
19 die("No such ref: %s", HEAD
);
20 else if (!(flag
& REF_ISSYMREF
)) {
22 die("ref %s is not a symbolic ref", HEAD
);
29 refname
= to_free
= shorten_unambiguous_ref(refname
, 0);
36 int cmd_symbolic_ref(int argc
, const char **argv
, const char *prefix
)
38 int quiet
= 0, delete = 0, shorten
= 0, ret
= 0;
39 const char *msg
= NULL
;
40 struct option options
[] = {
42 N_("suppress error message for non-symbolic (detached) refs")),
43 OPT_BOOL('d', "delete", &delete, N_("delete symbolic ref")),
44 OPT_BOOL(0, "short", &shorten
, N_("shorten ref output")),
45 OPT_STRING('m', NULL
, &msg
, N_("reason"), N_("reason of the update")),
49 git_config(git_default_config
, NULL
);
50 argc
= parse_options(argc
, argv
, prefix
, options
,
51 git_symbolic_ref_usage
, 0);
53 die("Refusing to perform update with empty message");
57 usage_with_options(git_symbolic_ref_usage
, options
);
58 ret
= check_symref(argv
[0], 1, 0, 0);
60 die("Cannot delete %s, not a symbolic ref", argv
[0]);
61 if (!strcmp(argv
[0], "HEAD"))
62 die("deleting '%s' is not allowed", argv
[0]);
63 return delete_ref(NULL
, argv
[0], NULL
, REF_NO_DEREF
);
68 ret
= check_symref(argv
[0], quiet
, shorten
, 1);
71 if (!strcmp(argv
[0], "HEAD") &&
72 !starts_with(argv
[1], "refs/"))
73 die("Refusing to point HEAD outside of refs/");
74 ret
= !!create_symref(argv
[0], argv
[1], msg
);
77 usage_with_options(git_symbolic_ref_usage
, options
);