check-ref-format --branch: give Porcelain a way to grok branch shorthand
[git] / builtin-check-ref-format.c
1 /*
2  * GIT - The information manager from hell
3  */
4
5 #include "cache.h"
6 #include "refs.h"
7 #include "builtin.h"
8 #include "strbuf.h"
9
10 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
11 {
12         if (argc == 3 && !strcmp(argv[1], "--branch")) {
13                 struct strbuf sb = STRBUF_INIT;
14                 strbuf_branchname(&sb, argv[2]);
15                 strbuf_splice(&sb, 0, 0, "refs/heads/", 11);
16                 if (check_ref_format(sb.buf))
17                         die("'%s' is not a valid branch name", argv[2]);
18                 printf("%s\n", sb.buf + 11);
19                 exit(0);
20         }
21         if (argc != 2)
22                 usage("git check-ref-format refname");
23         return !!check_ref_format(argv[1]);
24 }