4 #include "parse-options.h"
6 static const char * const git_symbolic_ref_usage[] = {
7 N_("git symbolic-ref [options] name [ref]"),
8 N_("git symbolic-ref -d [-q] name"),
12 static int check_symref(const char *HEAD, int quiet, int shorten, int print)
14 unsigned char sha1[20];
16 const char *refname = resolve_ref_unsafe(HEAD, sha1, 0, &flag);
19 die("No such ref: %s", HEAD);
20 else if (!(flag & REF_ISSYMREF)) {
22 die("ref %s is not a symbolic ref", HEAD);
28 refname = shorten_unambiguous_ref(refname, 0);
34 int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
36 int quiet = 0, delete = 0, shorten = 0, ret = 0;
37 const char *msg = NULL;
38 struct option options[] = {
40 N_("suppress error message for non-symbolic (detached) refs")),
41 OPT_BOOL('d', "delete", &delete, N_("delete symbolic ref")),
42 OPT_BOOL(0, "short", &shorten, N_("shorten ref output")),
43 OPT_STRING('m', NULL, &msg, N_("reason"), N_("reason of the update")),
47 git_config(git_default_config, NULL);
48 argc = parse_options(argc, argv, prefix, options,
49 git_symbolic_ref_usage, 0);
51 die("Refusing to perform update with empty message");
55 usage_with_options(git_symbolic_ref_usage, options);
56 ret = check_symref(argv[0], 1, 0, 0);
58 die("Cannot delete %s, not a symbolic ref", argv[0]);
59 return delete_ref(argv[0], NULL, REF_NODEREF);
64 ret = check_symref(argv[0], quiet, shorten, 1);
67 if (!strcmp(argv[0], "HEAD") &&
68 !starts_with(argv[1], "refs/"))
69 die("Refusing to point HEAD outside of refs/");
70 create_symref(argv[0], argv[1], msg);
73 usage_with_options(git_symbolic_ref_usage, options);