summaryrefslogtreecommitdiff
path: root/builtin/check-ref-format.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-11-15 12:04:57 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-11-15 12:04:57 +0900
commit3be9ac7e56d4bb4ae805543a91de5987e148b661 (patch)
treeb0ea94ad987a76b159765993d5a70326a4732136 /builtin/check-ref-format.c
parentMerge branch 'jc/t5601-copy-workaround' into maint (diff)
parentcheck-ref-format doc: --branch validates and expands <branch> (diff)
downloadtgif-3be9ac7e56d4bb4ae805543a91de5987e148b661.tar.xz
Merge branch 'jc/check-ref-format-oor' into maint
"git check-ref-format --branch @{-1}" bit a "BUG()" when run outside a repository for obvious reasons; clarify the documentation and make sure we do not even try to expand the at-mark magic in such a case, but still call the validation logic for branch names. * jc/check-ref-format-oor: check-ref-format doc: --branch validates and expands <branch> check-ref-format --branch: strip refs/heads/ using skip_prefix check-ref-format --branch: do not expand @{...} outside repository
Diffstat (limited to 'builtin/check-ref-format.c')
-rw-r--r--builtin/check-ref-format.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 6c40ff110b..bc67d3f0a8 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -39,12 +39,14 @@ static char *collapse_slashes(const char *refname)
static int check_ref_format_branch(const char *arg)
{
struct strbuf sb = STRBUF_INIT;
+ const char *name;
int nongit;
setup_git_directory_gently(&nongit);
- if (strbuf_check_branch_ref(&sb, arg))
+ if (strbuf_check_branch_ref(&sb, arg) ||
+ !skip_prefix(sb.buf, "refs/heads/", &name))
die("'%s' is not a valid branch name", arg);
- printf("%s\n", sb.buf + 11);
+ printf("%s\n", name);
strbuf_release(&sb);
return 0;
}