Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | |
| 3 | static const char git_symbolic_ref_usage[] = |
| 4 | "git-symbolic-ref name [ref]"; |
| 5 | |
Junio C Hamano | f5a5e9b | 2005-10-03 19:11:32 -0700 | [diff] [blame] | 6 | static void check_symref(const char *HEAD) |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 7 | { |
| 8 | unsigned char sha1[20]; |
| 9 | const char *git_HEAD = strdup(git_path("%s", HEAD)); |
| 10 | const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0); |
| 11 | if (git_refs_heads_master) { |
| 12 | /* we want to strip the .git/ part */ |
| 13 | int pfxlen = strlen(git_HEAD) - strlen(HEAD); |
| 14 | puts(git_refs_heads_master + pfxlen); |
| 15 | } |
| 16 | else |
| 17 | die("No such ref: %s", HEAD); |
| 18 | } |
| 19 | |
| 20 | int main(int argc, const char **argv) |
| 21 | { |
| 22 | setup_git_directory(); |
Johannes Schindelin | f8348be | 2005-11-15 19:24:19 +0100 | [diff] [blame] | 23 | git_config(git_default_config); |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 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 | } |