summaryrefslogtreecommitdiff
path: root/t/t6300-for-each-ref.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-11-18 23:21:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-11-18 23:21:12 (GMT)
commit84679d470d577bcde1b6aa6af36c08a2d77b6e68 (patch)
treea42f20ac63cfacfcff3a25256592f41c22745961 /t/t6300-for-each-ref.sh
parent0b65a8dbdb38962e700ee16776a3042beb489060 (diff)
downloadgit-84679d470d577bcde1b6aa6af36c08a2d77b6e68.zip
git-84679d470d577bcde1b6aa6af36c08a2d77b6e68.tar.gz
git-84679d470d577bcde1b6aa6af36c08a2d77b6e68.tar.bz2
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 be used to reimplement "git branch [--list]" in the future. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6300-for-each-ref.sh')
-rwxr-xr-xt/t6300-for-each-ref.sh10
1 files changed, 10 insertions, 0 deletions
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 19a2823..039509a 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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