]>
Commit | Line | Data |
---|---|---|
640ce105 | 1 | #include "builtin.h" |
8098a178 | 2 | #include "cache.h" |
8da19775 | 3 | #include "refs.h" |
8098a178 JH |
4 | |
5 | static const char git_symbolic_ref_usage[] = | |
8b5157e4 | 6 | "git-symbolic-ref [-q] [-m <reason>] name [ref]"; |
8098a178 | 7 | |
a0f4280f | 8 | static void check_symref(const char *HEAD, int quiet) |
8098a178 JH |
9 | { |
10 | unsigned char sha1[20]; | |
8da19775 JH |
11 | int flag; |
12 | const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag); | |
ed378ec7 LT |
13 | |
14 | if (!refs_heads_master) | |
8098a178 | 15 | die("No such ref: %s", HEAD); |
a0f4280f JH |
16 | else if (!(flag & REF_ISSYMREF)) { |
17 | if (!quiet) | |
18 | die("ref %s is not a symbolic ref", HEAD); | |
19 | else | |
20 | exit(1); | |
21 | } | |
ed378ec7 | 22 | puts(refs_heads_master); |
8098a178 JH |
23 | } |
24 | ||
640ce105 | 25 | int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) |
8098a178 | 26 | { |
a0f4280f | 27 | int quiet = 0; |
8b5157e4 | 28 | const char *msg = NULL; |
a0f4280f | 29 | |
27dedf0c | 30 | git_config(git_default_config); |
a0f4280f JH |
31 | |
32 | while (1 < argc) { | |
33 | const char *arg = argv[1]; | |
34 | if (arg[0] != '-') | |
35 | break; | |
36 | else if (!strcmp("-q", arg)) | |
37 | quiet = 1; | |
8b5157e4 NP |
38 | else if (!strcmp("-m", arg)) { |
39 | argc--; | |
40 | argv++; | |
41 | if (argc <= 1) | |
42 | break; | |
43 | msg = argv[1]; | |
44 | if (!*msg) | |
45 | die("Refusing to perform update with empty message"); | |
46 | if (strchr(msg, '\n')) | |
47 | die("Refusing to perform update with \\n in message"); | |
48 | } | |
a0f4280f JH |
49 | else if (!strcmp("--", arg)) { |
50 | argc--; | |
51 | argv++; | |
52 | break; | |
53 | } | |
54 | else | |
55 | die("unknown option %s", arg); | |
56 | argc--; | |
57 | argv++; | |
58 | } | |
59 | ||
8098a178 JH |
60 | switch (argc) { |
61 | case 2: | |
a0f4280f | 62 | check_symref(argv[1], quiet); |
8098a178 JH |
63 | break; |
64 | case 3: | |
8b5157e4 | 65 | create_symref(argv[1], argv[2], msg); |
8098a178 JH |
66 | break; |
67 | default: | |
68 | usage(git_symbolic_ref_usage); | |
69 | } | |
70 | return 0; | |
71 | } |