commit-tree: add missing --gpg-sign flag
Add --gpg-sign option in commit-tree, which was documented, but not implemented, in 55ca3f99ae. Add tests for the --gpg-sign option. Signed-off-by: Brandon Richardson <brandon1024.br@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Richardson committed
Jan 19, 2019 at 19:23 UTC
70ddbd7767c24076975a176e734767facd3b5380
2 files changed
+19
-4
builtin/commit-tree.c
+7
-1
@@ -66,7 +66,13 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
66
continue;
67
}
68
69
- if (skip_prefix(arg, "-S", &sign_commit))
69
+ if (!strcmp(arg, "--gpg-sign")) {
70
+ sign_commit = "";
71
+ continue;
72
+ }
73
+
74
+ if (skip_prefix(arg, "-S", &sign_commit) ||
75
+ skip_prefix(arg, "--gpg-sign=", &sign_commit))
76
continue;
77
78
if (!strcmp(arg, "--no-gpg-sign")) {
t/t7510-signed-commit.sh
+12
-3
@@ -55,13 +55,22 @@ test_expect_success GPG 'create signed commits' '
55
# explicit -S of course must sign.
56
echo 10 | git commit-tree -S HEAD^{tree} >oid &&
57
test_line_count = 1 oid &&
58
- git tag tenth-signed $(cat oid)
58
+ git tag tenth-signed $(cat oid) &&
59
+
60
+ # --gpg-sign[=<key-id>] must sign.
61
+ echo 11 | git commit-tree --gpg-sign HEAD^{tree} >oid &&
62
+ test_line_count = 1 oid &&
63
+ git tag eleventh-signed $(cat oid) &&
64
+ echo 12 | git commit-tree --gpg-sign=B7227189 HEAD^{tree} >oid &&
65
+ test_line_count = 1 oid &&
66
+ git tag twelfth-signed-alt $(cat oid)
67
'
68
69
test_expect_success GPG 'verify and show signatures' '
70
(
71
for commit in initial second merge fourth-signed \
64
- fifth-signed sixth-signed seventh-signed tenth-signed
72
+ fifth-signed sixth-signed seventh-signed tenth-signed \
73
+ eleventh-signed
74
do
75
git verify-commit $commit &&
76
git show --pretty=short --show-signature $commit >actual &&
@@ -82,7 +91,7 @@ test_expect_success GPG 'verify and show signatures' '
91
done
92
) &&
93
(
85
- for commit in eighth-signed-alt
94
+ for commit in eighth-signed-alt twelfth-signed-alt
95
do
96
git show --pretty=short --show-signature $commit >actual &&
97
grep "Good signature from" actual &&