]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-check-ref-format.c
git check-ref-format --print
[thirdparty/git.git] / builtin-check-ref-format.c
CommitLineData
9370bae2
LS
1/*
2 * GIT - The information manager from hell
3 */
4
5#include "cache.h"
6#include "refs.h"
7#include "builtin.h"
a31dca03 8#include "strbuf.h"
9370bae2 9
a633fca0 10int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
9370bae2 11{
a31dca03
JH
12 if (argc == 3 && !strcmp(argv[1], "--branch")) {
13 struct strbuf sb = STRBUF_INIT;
a2fab531
JH
14
15 if (strbuf_check_branch_ref(&sb, argv[2]))
a31dca03
JH
16 die("'%s' is not a valid branch name", argv[2]);
17 printf("%s\n", sb.buf + 11);
18 exit(0);
19 }
38eedc63
JH
20 if (argc == 3 && !strcmp(argv[1], "--print")) {
21 char *refname = xmalloc(strlen(argv[2]) + 1);
22
23 if (check_ref_format(argv[2]))
24 exit(1);
25 if (normalize_path_copy(refname, argv[2]))
26 die("Could not normalize ref name '%s'", argv[2]);
27 printf("%s\n", refname);
28 exit(0);
29 }
9370bae2 30 if (argc != 2)
34baebce 31 usage("git check-ref-format refname");
9370bae2
LS
32 return !!check_ref_format(argv[1]);
33}