]>
git.ipfire.org Git - thirdparty/git.git/blob - builtin-symbolic-ref.c
4 #include "parse-options.h"
6 static const char * const git_symbolic_ref_usage
[] = {
7 "git symbolic-ref [options] name [ref]",
11 static void check_symref(const char *HEAD
, int quiet
)
13 unsigned char sha1
[20];
15 const char *refs_heads_master
= resolve_ref(HEAD
, sha1
, 0, &flag
);
17 if (!refs_heads_master
)
18 die("No such ref: %s", HEAD
);
19 else if (!(flag
& REF_ISSYMREF
)) {
21 die("ref %s is not a symbolic ref", HEAD
);
25 puts(refs_heads_master
);
28 int cmd_symbolic_ref(int argc
, const char **argv
, const char *prefix
)
31 const char *msg
= NULL
;
32 struct option options
[] = {
34 OPT_STRING('m', NULL
, &msg
, "reason", "reason of the update"),
38 git_config(git_default_config
, NULL
);
39 argc
= parse_options(argc
, argv
, prefix
, options
,
40 git_symbolic_ref_usage
, 0);
42 die("Refusing to perform update with empty message");
45 check_symref(argv
[0], quiet
);
48 if (!strcmp(argv
[0], "HEAD") &&
49 prefixcmp(argv
[1], "refs/"))
50 die("Refusing to point HEAD outside of refs/");
51 create_symref(argv
[0], argv
[1], msg
);
54 usage_with_options(git_symbolic_ref_usage
, options
);