]>
Commit | Line | Data |
---|---|---|
640ce105 | 1 | #include "builtin.h" |
8098a178 JH |
2 | #include "cache.h" |
3 | ||
4 | static const char git_symbolic_ref_usage[] = | |
5 | "git-symbolic-ref name [ref]"; | |
6 | ||
f5a5e9b9 | 7 | static void check_symref(const char *HEAD) |
8098a178 JH |
8 | { |
9 | unsigned char sha1[20]; | |
10 | const char *git_HEAD = strdup(git_path("%s", HEAD)); | |
11 | const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0); | |
12 | if (git_refs_heads_master) { | |
13 | /* we want to strip the .git/ part */ | |
14 | int pfxlen = strlen(git_HEAD) - strlen(HEAD); | |
15 | puts(git_refs_heads_master + pfxlen); | |
16 | } | |
17 | else | |
18 | die("No such ref: %s", HEAD); | |
19 | } | |
20 | ||
640ce105 | 21 | int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) |
8098a178 | 22 | { |
27dedf0c | 23 | git_config(git_default_config); |
8098a178 JH |
24 | switch (argc) { |
25 | case 2: | |
26 | check_symref(argv[1]); | |
27 | break; | |
28 | case 3: | |
29 | create_symref(strdup(git_path("%s", argv[1])), argv[2]); | |
30 | break; | |
31 | default: | |
32 | usage(git_symbolic_ref_usage); | |
33 | } | |
34 | return 0; | |
35 | } |