Skip to content

Commit 48e9ad5

Browse files
committed
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
2 parents 1e37181 + 84679d4 commit 48e9ad5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ static void populate_value(struct ref_array_item *ref)
10171017

10181018
head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
10191019
sha1, NULL);
1020-
if (!strcmp(ref->refname, head))
1020+
if (head && !strcmp(ref->refname, head))
10211021
v->s = "*";
10221022
else
10231023
v->s = " ";

t/t6300-for-each-ref.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,14 @@ test_expect_success 'Verify sort with multiple keys' '
553553
refs/tags/bogo refs/tags/master > actual &&
554554
test_cmp expected actual
555555
'
556+
557+
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
558+
test_when_finished "git checkout master" &&
559+
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
560+
sed -e "s/^\* / /" actual >expect &&
561+
git checkout --orphan HEAD &&
562+
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
563+
test_cmp expect actual
564+
'
565+
556566
test_done

0 commit comments

Comments
 (0)