t5531: avoid using an abbreviated option
[gitweb.git] / t / t4205-log-pretty-formats.sh
index 2052cadb1109d3644b0c3f82b707f8e8bb35f945..f42a69faa2fde46d958577d10c50d2a6379ebf60 100755 (executable)
@@ -578,6 +578,24 @@ test_expect_success '%(trailers:only) shows only "key: value" trailers' '
        test_cmp expect actual
 '
 
+test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' '
+       git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
+       grep -v patch.description <trailers >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:only=no) shows all trailers' '
+       git log --no-walk --pretty=format:"%(trailers:only=no)" >actual &&
+       cat trailers >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' '
+       git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
+       grep -v patch.description <trailers >expect &&
+       test_cmp expect actual
+'
+
 test_expect_success '%(trailers:unfold) unfolds trailers' '
        git log --no-walk --pretty="%(trailers:unfold)" >actual &&
        {
@@ -598,4 +616,176 @@ test_expect_success ':only and :unfold work together' '
        test_cmp expect actual
 '
 
+test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' '
+       git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual &&
+       echo "Acked-by: A U Thor <author@example.com>" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' '
+       git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual &&
+       echo "Acked-by: A U Thor <author@example.com>" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' '
+       git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual &&
+       echo "Acked-by: A U Thor <author@example.com>" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers:key=foo) multiple keys' '
+       git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual &&
+       grep -v patch.description <trailers >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:key=nonexistant) becomes empty' '
+       git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual &&
+       echo "xx" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' '
+       git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual &&
+       grep -v patch.description <trailers | grep -v Acked-by >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:key=foo,unfold) properly unfolds' '
+       git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual &&
+       unfold <trailers | grep Signed-off-by >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' '
+       git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual &&
+       {
+               echo "Acked-by: A U Thor <author@example.com>" &&
+               grep patch.description <trailers
+       } >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:key) without value is error' '
+       git log --no-walk --pretty="tformat:%(trailers:key)" >actual &&
+       echo "%(trailers:key)" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '%(trailers:key=foo,valueonly) shows only value' '
+       git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual &&
+       echo "A U Thor <author@example.com>" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers:separator) changes separator' '
+       git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual &&
+       printf "XSigned-off-by: A U Thor <author@example.com>\0Acked-by: A U Thor <author@example.com>\0[ v2 updated patch description ]\0Signed-off-by: A U Thor <author@example.com>X" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pretty format %(trailers) combining separator/key/valueonly' '
+       git commit --allow-empty -F - <<-\EOF &&
+       Important fix
+
+       The fix is explained here
+
+       Closes: #1234
+       EOF
+
+       git commit --allow-empty -F - <<-\EOF &&
+       Another fix
+
+       The fix is explained here
+
+       Closes: #567
+       Closes: #890
+       EOF
+
+       git commit --allow-empty -F - <<-\EOF &&
+       Does not close any tickets
+       EOF
+
+       git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual &&
+       test_write_lines \
+               "Does not close any tickets" \
+               "Another fix #567, #890" \
+               "Important fix #1234" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'trailer parsing not fooled by --- line' '
+       git commit --allow-empty -F - <<-\EOF &&
+       this is the subject
+
+       This is the body. The message has a "---" line which would confuse a
+       message+patch parser. But here we know we have only a commit message,
+       so we get it right.
+
+       trailer: wrong
+       ---
+       This is more body.
+
+       trailer: right
+       EOF
+
+       {
+               echo "trailer: right" &&
+               echo
+       } >expect &&
+       git log --no-walk --format="%(trailers)" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'set up %S tests' '
+       git checkout --orphan source-a &&
+       test_commit one &&
+       test_commit two &&
+       git checkout -b source-b HEAD^ &&
+       test_commit three
+'
+
+test_expect_success 'log --format=%S paints branch names' '
+       cat >expect <<-\EOF &&
+       source-b
+       source-a
+       source-b
+       EOF
+       git log --format=%S source-a source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints tag names' '
+       git tag -m tagged source-tag &&
+       cat >expect <<-\EOF &&
+       source-tag
+       source-a
+       source-tag
+       EOF
+       git log --format=%S source-tag source-a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints symmetric ranges' '
+       cat >expect <<-\EOF &&
+       source-b
+       source-a
+       EOF
+       git log --format=%S source-a...source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 1)' '
+       git log --format="source-b %h" source-b >expect &&
+       git log --format="%S %h" source-b >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 2)' '
+       git log --format="%h source-b" source-b >expect &&
+       git log --format="%h %S" source-b >actual &&
+       test_cmp expect actual
+'
+
 test_done