1
0
mirror of https://github.com/git/git.git synced 2024-09-21 19:01:40 +02:00

Merge branch 'jc/for-each-ref-head-segfault-fix'

Using a %(HEAD) placeholder in "for-each-ref --format=" option
caused the command to segfault when on an unborn branch.

* jc/for-each-ref-head-segfault-fix:
  for-each-ref: do not segv with %(HEAD) on an unborn branch
This commit is contained in:
Junio C Hamano 2016-11-23 11:23:16 -08:00
commit 48e9ad5ef3
2 changed files with 11 additions and 1 deletions

View File

@ -1017,7 +1017,7 @@ static void populate_value(struct ref_array_item *ref)
head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
sha1, NULL);
if (!strcmp(ref->refname, head))
if (head && !strcmp(ref->refname, head))
v->s = "*";
else
v->s = " ";

View File

@ -553,4 +553,14 @@ test_expect_success 'Verify sort with multiple keys' '
refs/tags/bogo refs/tags/master > actual &&
test_cmp expected actual
'
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
test_when_finished "git checkout master" &&
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
sed -e "s/^\* / /" actual >expect &&
git checkout --orphan HEAD &&
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
test_cmp expect actual
'
test_done