@@ -49,11 +49,17 @@ test_atom() {
4949}
5050
5151test_atom head refname refs/heads/master
52+ test_atom head refname:short master
53+ test_atom head refname:strip=1 heads/master
54+ test_atom head refname:strip=2 master
5255test_atom head upstream refs/remotes/origin/master
56+ test_atom head upstream:short origin/master
5357test_atom head push refs/remotes/myfork/master
58+ test_atom head push:short myfork/master
5459test_atom head objecttype commit
5560test_atom head objectsize 171
5661test_atom head objectname $( git rev-parse refs/heads/master)
62+ test_atom head objectname:short $( git rev-parse --short refs/heads/master)
5763test_atom head tree $( git rev-parse refs/heads/master^{tree})
5864test_atom head parent ' '
5965test_atom head numparent 0
@@ -86,11 +92,13 @@ test_atom head contents 'Initial
8692test_atom head HEAD ' *'
8793
8894test_atom tag refname refs/tags/testtag
95+ test_atom tag refname:short testtag
8996test_atom tag upstream ' '
9097test_atom tag push ' '
9198test_atom tag objecttype tag
9299test_atom tag objectsize 154
93100test_atom tag objectname $( git rev-parse refs/tags/testtag)
101+ test_atom tag objectname:short $( git rev-parse --short refs/tags/testtag)
94102test_atom tag tree ' '
95103test_atom tag parent ' '
96104test_atom tag numparent ' '
@@ -126,6 +134,16 @@ test_expect_success 'Check invalid atoms names are errors' '
126134 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
127135'
128136
137+ test_expect_success ' arguments to :strip must be positive integers' '
138+ test_must_fail git for-each-ref --format="%(refname:strip=0)" &&
139+ test_must_fail git for-each-ref --format="%(refname:strip=-1)" &&
140+ test_must_fail git for-each-ref --format="%(refname:strip=foo)"
141+ '
142+
143+ test_expect_success ' stripping refnames too far gives an error' '
144+ test_must_fail git for-each-ref --format="%(refname:strip=3)"
145+ '
146+
129147test_expect_success ' Check format specifiers are ignored in naming date atoms' '
130148 git for-each-ref --format="%(authordate)" refs/heads &&
131149 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
@@ -338,47 +356,14 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
338356 "
339357done
340358
341- cat > expected << \EOF
342- master
343- testtag
344- EOF
345-
346- test_expect_success ' Check short refname format' '
347- (git for-each-ref --format="%(refname:short)" refs/heads &&
348- git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
349- test_cmp expected actual
350- '
351-
352- cat > expected << EOF
353- origin/master
354- EOF
355-
356- test_expect_success ' Check short upstream format' '
357- git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
358- test_cmp expected actual
359- '
360-
361359test_expect_success ' setup for upstream:track[short]' '
362360 test_commit two
363361'
364362
365- cat > expected << EOF
366- [ahead 1]
367- EOF
368-
369- test_expect_success ' Check upstream:track format' '
370- git for-each-ref --format="%(upstream:track)" refs/heads >actual &&
371- test_cmp expected actual
372- '
373-
374- cat > expected << EOF
375- >
376- EOF
377-
378- test_expect_success ' Check upstream:trackshort format' '
379- git for-each-ref --format="%(upstream:trackshort)" refs/heads >actual &&
380- test_cmp expected actual
381- '
363+ test_atom head upstream:track ' [ahead 1]'
364+ test_atom head upstream:trackshort ' >'
365+ test_atom head push:track ' [ahead 1]'
366+ test_atom head push:trackshort ' >'
382367
383368test_expect_success ' Check that :track[short] cannot be used with other atoms' '
384369 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
@@ -398,21 +383,6 @@ test_expect_success 'Check that :track[short] works when upstream is invalid' '
398383 test_cmp expected actual
399384'
400385
401- test_expect_success ' %(push) supports tracking specifiers, too' '
402- echo "[ahead 1]" >expected &&
403- git for-each-ref --format="%(push:track)" refs/heads >actual &&
404- test_cmp expected actual
405- '
406-
407- cat > expected << EOF
408- $( git rev-parse --short HEAD)
409- EOF
410-
411- test_expect_success ' Check short objectname format' '
412- git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
413- test_cmp expected actual
414- '
415-
416386test_expect_success ' Check for invalid refname format' '
417387 test_must_fail git for-each-ref --format="%(refname:INVALID)"
418388'
0 commit comments