Merge branch 'jk/pretty-G-format-fixes'
authorJunio C Hamano <gitster@pobox.com>
Wed, 9 Jul 2014 18:34:13 +0000 (11:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Jul 2014 18:34:13 +0000 (11:34 -0700)
* jk/pretty-G-format-fixes:
move "%G" format test from t7510 to t6006
pretty: avoid reading past end-of-string with "%G"
t7510: check %G* pretty-format output
t7510: test a commit signed by an unknown key
t7510: use consistent &&-chains in loop
t7510: stop referring to master in later tests

pretty.c
t/t6006-rev-list-format.sh
t/t7510-signed-commit.sh
index b5cf3d52c3228a06689c847a3202bedf95f00dcf..8d201f6bda1bb9ccf97be4fa25660adbebcfe74f 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1248,6 +1248,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                        if (c->signature_check.key)
                                strbuf_addstr(sb, c->signature_check.key);
                        break;
+               default:
+                       return 0;
                }
                return 2;
        }
index c277db64f75ac9f9c0cd617262824d76959fbfbd..88ed3191e871cd9a164c3c903f69b07e7d9cf937 100755 (executable)
@@ -468,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
        test_cmp expect actual
 '
 
+test_expect_success 'unused %G placeholders are passed through' '
+       echo "%GX %G" >expect &&
+       git log -1 --format="%GX %G" >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 5ddac1a9f740c03f1d94f75db2c6e54dd3391eda..e97477a3b98a49c80ce01f06b966eacff52a3bd1 100755 (executable)
@@ -43,31 +43,44 @@ test_expect_success GPG 'create signed commits' '
 
        test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
        git tag seventh-signed
+
+       echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
+       git tag eighth-signed-alt
 '
 
 test_expect_success GPG 'show signatures' '
        (
-               for commit in initial second merge fourth-signed fifth-signed sixth-signed master
+               for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
                do
                        git show --pretty=short --show-signature $commit >actual &&
-                       grep "Good signature from" actual || exit 1
-                       ! grep "BAD signature from" actual || exit 1
-                       echo $commit OK
+                       grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       echo $commit OK || exit 1
                done
        ) &&
        (
                for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
                do
                        git show --pretty=short --show-signature $commit >actual &&
-                       grep "Good signature from" actual && exit 1
-                       ! grep "BAD signature from" actual || exit 1
-                       echo $commit OK
+                       ! grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       echo $commit OK || exit 1
+               done
+       ) &&
+       (
+               for commit in eighth-signed-alt
+               do
+                       git show --pretty=short --show-signature $commit >actual &&
+                       grep "Good signature from" actual &&
+                       ! grep "BAD signature from" actual &&
+                       grep "not certified" actual &&
+                       echo $commit OK || exit 1
                done
        )
 '
 
 test_expect_success GPG 'detect fudged signature' '
-       git cat-file commit master >raw &&
+       git cat-file commit seventh-signed >raw &&
 
        sed -e "s/seventh/7th forged/" raw >forged1 &&
        git hash-object -w -t commit forged1 >forged1.commit &&
@@ -77,7 +90,7 @@ test_expect_success GPG 'detect fudged signature' '
 '
 
 test_expect_success GPG 'detect fudged signature with NUL' '
-       git cat-file commit master >raw &&
+       git cat-file commit seventh-signed >raw &&
        cat raw >forged2 &&
        echo Qwik | tr "Q" "\000" >>forged2 &&
        git hash-object -w -t commit forged2 >forged2.commit &&
@@ -94,4 +107,44 @@ test_expect_success GPG 'amending already signed commit' '
        ! grep "BAD signature from" actual
 '
 
+test_expect_success GPG 'show good signature with custom format' '
+       cat >expect <<-\EOF &&
+       G
+       13B6F51ECDDE430D
+       C O Mitter <committer@example.com>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show bad signature with custom format' '
+       cat >expect <<-\EOF &&
+       B
+       13B6F51ECDDE430D
+       C O Mitter <committer@example.com>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show unknown signature with custom format' '
+       cat >expect <<-\EOF &&
+       U
+       61092E85B7227189
+       Eris Discordia <discord@example.net>
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success GPG 'show lack of signature with custom format' '
+       cat >expect <<-\EOF &&
+       N
+
+
+       EOF
+       git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
+       test_cmp expect actual
+'
+
 test_done