pretty: add support for separator option in %(trailers)
[gitweb.git] / t / t4205-log-pretty-formats.sh
index 591f35daaf5825cfdcf8e7fccf4f52462bbf8f78..99f50fa401cbddc7df508d55b3f876728b97047f 100755 (executable)
@@ -516,22 +516,22 @@ test_expect_success 'log decoration properly follows tag chain' '
        git commit --amend -m shorter &&
        git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
        cat <<-EOF >expected &&
-       $head1  (tag: refs/tags/tag2)
        $head2  (tag: refs/tags/message-one)
        $old_head1  (tag: refs/tags/message-two)
+       $head1  (tag: refs/tags/tag2)
        EOF
-       sort actual >actual1 &&
+       sort -k3 actual >actual1 &&
        test_cmp expected actual1
 '
 
 test_expect_success 'clean log decoration' '
        git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
        cat >expected <<-EOF &&
-       $head1 tag: refs/tags/tag2
        $head2 tag: refs/tags/message-one
        $old_head1 tag: refs/tags/message-two
+       $head1 tag: refs/tags/tag2
        EOF
-       sort actual >actual1 &&
+       sort -k3 actual >actual1 &&
        test_cmp expected actual1
 '
 
@@ -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,126 @@ 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_done