Skip to content

Commit 01f9582

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: make "%(symref)" atom work with the ':short' modifier
The "%(symref)" atom doesn't work when used with the ':short' modifier because we strictly match only 'symref' for setting the 'need_symref' indicator. Fix this by comparing with the valid_atom rather than the used_atom. Add tests for %(symref) and %(symref:short) while we're here. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Karthik Nayak <Karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7743fcc commit 01f9582

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
352352
valid_atom[i].parser(&used_atom[at], arg);
353353
if (*atom == '*')
354354
need_tagged = 1;
355-
if (!strcmp(used_atom[at].name, "symref"))
355+
if (!strcmp(valid_atom[i].name, "symref"))
356356
need_symref = 1;
357357
return at;
358358
}

t/t6300-for-each-ref.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test_atom() {
3838
case "$1" in
3939
head) ref=refs/heads/master ;;
4040
tag) ref=refs/tags/testtag ;;
41+
sym) ref=refs/heads/sym ;;
4142
*) ref=$1 ;;
4243
esac
4344
printf '%s\n' "$3" >expected
@@ -566,6 +567,7 @@ test_expect_success 'Verify sort with multiple keys' '
566567
test_cmp expected actual
567568
'
568569

570+
569571
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
570572
test_when_finished "git checkout master" &&
571573
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
@@ -600,4 +602,26 @@ test_expect_success 'basic atom: head contents:trailers' '
600602
test_cmp expect actual.clean
601603
'
602604

605+
test_expect_success 'Add symbolic ref for the following tests' '
606+
git symbolic-ref refs/heads/sym refs/heads/master
607+
'
608+
609+
cat >expected <<EOF
610+
refs/heads/master
611+
EOF
612+
613+
test_expect_success 'Verify usage of %(symref) atom' '
614+
git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
615+
test_cmp expected actual
616+
'
617+
618+
cat >expected <<EOF
619+
heads/master
620+
EOF
621+
622+
test_expect_success 'Verify usage of %(symref:short) atom' '
623+
git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
624+
test_cmp expected actual
625+
'
626+
603627
test_done

0 commit comments

Comments
 (0)