Junio C Hamano <gitster@xxxxxxxxx> writes: > Something like this needs to go before that step. This time with a log message and an additional test. The second paragraph of the proposed log message is written expecting that this patch will come before your "branch: use ref-filter printing APIs", which I think is a good place to avoid breakage in the series. -- >8 -- Subject: [PATCH] for-each-ref: do not segv with %(HEAD) on an unborn branch The code to flip between "*" and " " prefixes depending on what branch is checked out used in --format='%(HEAD)' did not consider that HEAD may resolve to an unborn branch and dereferenced a NULL. This will become a lot easier to trigger as the codepath will now be shared with "git branch [--list]". Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- ref-filter.c | 2 +- t/t3203-branch-output.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ref-filter.c b/ref-filter.c index 944671af5a..c71d7360d2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1318,7 +1318,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 = " "; diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index d8edaf27e9..1a8dbca8c8 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -37,6 +37,14 @@ test_expect_success 'git branch --list shows local branches' ' test_cmp expect actual ' +test_expect_success 'same, but on an unborn branch' ' + test_when_finished "git checkout master" && + git checkout --orphan naster && + git branch --list >actual && + sed -e "s/\* / /" expect >expect-unborn && + test_cmp expect-unborn actual +' + cat >expect <<'EOF' branch-one branch-two -- 2.11.0-rc1-154-gcd2a643dcd