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>
Karthik Nayak committed
Jan 10, 2017 at 14:19 UTC
01f95825d55b2ca36ee9bc131a5f6899f47621c6
2 files changed
+25
-1
ref-filter.c
+1
-1
@@ -352,7 +352,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
352
valid_atom[i].parser(&used_atom[at], arg);
353
if (*atom == '*')
354
need_tagged = 1;
355
- if (!strcmp(used_atom[at].name, "symref"))
355
+ if (!strcmp(valid_atom[i].name, "symref"))
356
need_symref = 1;
357
return at;
358
}
t/t6300-for-each-ref.sh
+24
@@ -38,6 +38,7 @@ test_atom() {
38
case "$1" in
39
head) ref=refs/heads/master ;;
40
tag) ref=refs/tags/testtag ;;
41
+ sym) ref=refs/heads/sym ;;
42
*) ref=$1 ;;
43
esac
44
printf '%s\n' "$3" >expected
@@ -566,6 +567,7 @@ test_expect_success 'Verify sort with multiple keys' '
567
test_cmp expected actual
568
'
569
570
+
571
test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
572
test_when_finished "git checkout master" &&
573
git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
@@ -600,4 +602,26 @@ test_expect_success 'basic atom: head contents:trailers' '
602
test_cmp expect actual.clean
603
'
604
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
+
627
test_done