Skip to content

Commit 70ddbd7

Browse files
brandon1024gitster
authored andcommitted
commit-tree: add missing --gpg-sign flag
Add --gpg-sign option in commit-tree, which was documented, but not implemented, in 55ca3f9. Add tests for the --gpg-sign option. Signed-off-by: Brandon Richardson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41a74bd commit 70ddbd7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

builtin/commit-tree.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
6666
continue;
6767
}
6868

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))
7076
continue;
7177

7278
if (!strcmp(arg, "--no-gpg-sign")) {

t/t7510-signed-commit.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,22 @@ test_expect_success GPG 'create signed commits' '
5555
# explicit -S of course must sign.
5656
echo 10 | git commit-tree -S HEAD^{tree} >oid &&
5757
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)
5967
'
6068

6169
test_expect_success GPG 'verify and show signatures' '
6270
(
6371
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
6574
do
6675
git verify-commit $commit &&
6776
git show --pretty=short --show-signature $commit >actual &&
@@ -82,7 +91,7 @@ test_expect_success GPG 'verify and show signatures' '
8291
done
8392
) &&
8493
(
85-
for commit in eighth-signed-alt
94+
for commit in eighth-signed-alt twelfth-signed-alt
8695
do
8796
git show --pretty=short --show-signature $commit >actual &&
8897
grep "Good signature from" actual &&

0 commit comments

Comments
 (0)