Allow "check-ref-format --branch" from subdirectory
check-ref-format --branch requires access to the repository to resolve refs like @{-1}. Noticed by Nguyễn Thái Ngọc Duy. Cc: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 5, 2010 at 22:39 UTC
49cc460d88f5bae79b45ce2db16674f36b6cf38a
2 files changed
+19
builtin/check-ref-format.c
+2
@@ -36,7 +36,9 @@ static void collapse_slashes(char *dst, const char *src)
36
static int check_ref_format_branch(const char *arg)
37
{
38
struct strbuf sb = STRBUF_INIT;
39
+ int nongit;
40
41
+ setup_git_directory_gently(&nongit);
42
if (strbuf_check_branch_ref(&sb, arg))
43
die("'%s' is not a valid branch name", arg);
44
printf("%s\n", sb.buf + 11);
t/t1402-check-ref-format.sh
+17
@@ -41,6 +41,23 @@ test_expect_success "check-ref-format --branch @{-1}" '
41
refname2=$(git check-ref-format --branch @{-2}) &&
42
test "$refname2" = master'
43
44
+test_expect_success 'check-ref-format --branch from subdir' '
45
+ mkdir subdir &&
46
+
47
+ T=$(git write-tree) &&
48
+ sha1=$(echo A | git commit-tree $T) &&
49
+ git update-ref refs/heads/master $sha1 &&
50
+ git update-ref refs/remotes/origin/master $sha1
51
+ git checkout master &&
52
+ git checkout origin/master &&
53
+ git checkout master &&
54
+ refname=$(
55
+ cd subdir &&
56
+ git check-ref-format --branch @{-1}
57
+ ) &&
58
+ test "$refname" = "$sha1"
59
+'
60
+
61
valid_ref_normalized() {
62
test_expect_success "ref name '$1' simplifies to '$2'" "
63
refname=\$(git check-ref-format --print '$1') &&