ref-filter: make "%(symref)" atom work with the ':short' modifier
[gitweb.git] / t / t6300-for-each-ref.sh
index 039509a9cb94ef5c653df09e0453ac83157bf184..7663a3661f999f17e66766ea67279f9d350cd29c 100755 (executable)
@@ -38,6 +38,7 @@ test_atom() {
        case "$1" in
                head) ref=refs/heads/master ;;
                 tag) ref=refs/tags/testtag ;;
+                sym) ref=refs/heads/sym ;;
                   *) ref=$1 ;;
        esac
        printf '%s\n' "$3" >expected
@@ -60,6 +61,8 @@ test_atom head objecttype commit
 test_atom head objectsize 171
 test_atom head objectname $(git rev-parse refs/heads/master)
 test_atom head objectname:short $(git rev-parse --short refs/heads/master)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
 test_atom head tree $(git rev-parse refs/heads/master^{tree})
 test_atom head parent ''
 test_atom head numparent 0
@@ -99,6 +102,8 @@ test_atom tag objecttype tag
 test_atom tag objectsize 154
 test_atom tag objectname $(git rev-parse refs/tags/testtag)
 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
 test_atom tag tree ''
 test_atom tag parent ''
 test_atom tag numparent ''
@@ -164,6 +169,12 @@ test_expect_success 'Check invalid format specifiers are errors' '
        test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
 '
 
+test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
+       test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
+       test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
+       test_must_fail git for-each-ref --format="%(objectname:short=foo)"
+'
+
 test_date () {
        f=$1 &&
        committer_date=$2 &&
@@ -362,6 +373,8 @@ test_expect_success 'setup for upstream:track[short]' '
 
 test_atom head upstream:track '[ahead 1]'
 test_atom head upstream:trackshort '>'
+test_atom head upstream:track,nobracket 'ahead 1'
+test_atom head upstream:nobracket,track 'ahead 1'
 test_atom head push:track '[ahead 1]'
 test_atom head push:trackshort '>'
 
@@ -372,7 +385,7 @@ test_expect_success 'Check that :track[short] cannot be used with other atoms' '
 
 test_expect_success 'Check that :track[short] works when upstream is invalid' '
        cat >expected <<-\EOF &&
-
+       [gone]
 
        EOF
        test_when_finished "git config branch.master.merge refs/heads/master" &&
@@ -554,6 +567,7 @@ test_expect_success 'Verify sort with multiple keys' '
        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 &&
@@ -563,4 +577,51 @@ test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
        test_cmp expect actual
 '
 
+cat >trailers <<EOF
+Reviewed-by: A U Thor <author@example.com>
+Signed-off-by: A U Thor <author@example.com>
+EOF
+
+test_expect_success 'basic atom: head contents:trailers' '
+       echo "Some contents" > two &&
+       git add two &&
+       git commit -F - <<-EOF &&
+       trailers: this commit message has trailers
+
+       Some message contents
+
+       $(cat trailers)
+       EOF
+       git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
+       sanitize_pgp <actual >actual.clean &&
+       # git for-each-ref ends with a blank line
+       cat >expect <<-EOF &&
+       $(cat trailers)
+
+       EOF
+       test_cmp expect actual.clean
+'
+
+test_expect_success 'Add symbolic ref for the following tests' '
+       git symbolic-ref refs/heads/sym refs/heads/master
+'
+
+cat >expected <<EOF
+refs/heads/master
+EOF
+
+test_expect_success 'Verify usage of %(symref) atom' '
+       git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+heads/master
+EOF
+
+test_expect_success 'Verify usage of %(symref:short) atom' '
+       git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
+       test_cmp expected actual
+'
+
 test_done