Terminate argv with NULL before calling setup_revisions()
[git/dscho.git] / builtin-symbolic-ref.c
blob6ae6bcc0e8d02d9af8a81a7d694c0bfd2c6c0514
1 #include "builtin.h"
2 #include "cache.h"
3 #include "refs.h"
4 #include "parse-options.h"
6 static const char * const git_symbolic_ref_usage[] = {
7 "git symbolic-ref [options] name [ref]",
8 NULL
9 };
11 static void check_symref(const char *HEAD, int quiet)
13 unsigned char sha1[20];
14 int flag;
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)) {
20 if (!quiet)
21 die("ref %s is not a symbolic ref", HEAD);
22 else
23 exit(1);
25 puts(refs_heads_master);
28 int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
30 int quiet = 0;
31 const char *msg = NULL;
32 struct option options[] = {
33 OPT__QUIET(&quiet),
34 OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
35 OPT_END(),
38 git_config(git_default_config, NULL);
39 argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
40 if (msg &&!*msg)
41 die("Refusing to perform update with empty message");
42 switch (argc) {
43 case 1:
44 check_symref(argv[0], quiet);
45 break;
46 case 2:
47 if (!strcmp(argv[0], "HEAD") &&
48 prefixcmp(argv[1], "refs/"))
49 die("Refusing to point HEAD outside of refs/");
50 create_symref(argv[0], argv[1], msg);
51 break;
52 default:
53 usage_with_options(git_symbolic_ref_usage, options);
55 return 0;