Skip to content

Commit

Permalink
Allow "check-ref-format --branch" from subdirectory
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Aug 6, 2010
1 parent cfbe22f commit 49cc460
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/check-ref-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ static void collapse_slashes(char *dst, const char *src)
static int check_ref_format_branch(const char *arg)
{
struct strbuf sb = STRBUF_INIT;
int nongit;

setup_git_directory_gently(&nongit);
if (strbuf_check_branch_ref(&sb, arg))
die("'%s' is not a valid branch name", arg);
printf("%s\n", sb.buf + 11);
Expand Down
17 changes: 17 additions & 0 deletions t/t1402-check-ref-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ test_expect_success "check-ref-format --branch @{-1}" '
refname2=$(git check-ref-format --branch @{-2}) &&
test "$refname2" = master'

test_expect_success 'check-ref-format --branch from subdir' '
mkdir subdir &&
T=$(git write-tree) &&
sha1=$(echo A | git commit-tree $T) &&
git update-ref refs/heads/master $sha1 &&
git update-ref refs/remotes/origin/master $sha1
git checkout master &&
git checkout origin/master &&
git checkout master &&
refname=$(
cd subdir &&
git check-ref-format --branch @{-1}
) &&
test "$refname" = "$sha1"
'

valid_ref_normalized() {
test_expect_success "ref name '$1' simplifies to '$2'" "
refname=\$(git check-ref-format --print '$1') &&
Expand Down

0 comments on commit 49cc460

Please sign in to comment.