sequencer: fix gpg option passed to merge subcommand
When performing a rebase with --rebase-merges using either a custom strategy specified with -s or an octopus merge, and at the same time having gpgsign enabled (either rebase -S or config commit.gpgsign), the operation would fail on making the merge commit. Instead of "-S%s" with the key id substituted, only the bare key id would get passed to the underlying merge command, which tried to interpret it as a ref. Fix the issue and add test cases as suggested by Johannes Schindelin and Junio C Hamano. Signed-off-by: Samuel Čavoj <samuel@cavoj.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Samuel Čavoj committed
Oct 18, 2020 at 01:15 UTC
ae03c97ac0e36a33183562464f9506c8b3a73060
2 files changed
+22
-1
sequencer.c
+1
-1
@@ -3677,7 +3677,7 @@ static int do_merge(struct repository *r,
3677
strvec_push(&cmd.args, "-F");
3678
strvec_push(&cmd.args, git_path_merge_msg(r));
3679
if (opts->gpg_sign)
3680
- strvec_push(&cmd.args, opts->gpg_sign);
3680
+ strvec_pushf(&cmd.args, "-S%s", opts->gpg_sign);
3681
3682
/* Add the tips to be merged */
3683
for (j = to_merge; j; j = j->next)
t/t3435-rebase-gpg-sign.sh
+21
@@ -68,4 +68,25 @@ test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' '
68
test_must_fail git verify-commit HEAD
69
'
70
71
+test_expect_success 'rebase -r, merge strategy, --gpg-sign will sign commit' '
72
+ git reset --hard merged &&
73
+ test_unconfig commit.gpgsign &&
74
+ git rebase -fr --gpg-sign -s resolve --root &&
75
+ git verify-commit HEAD
76
+'
77
+
78
+test_expect_success 'rebase -r, merge strategy, commit.gpgsign=true will sign commit' '
79
+ git reset --hard merged &&
80
+ git config commit.gpgsign true &&
81
+ git rebase -fr -s resolve --root &&
82
+ git verify-commit HEAD
83
+'
84
+
85
+test_expect_success 'rebase -r, merge strategy, commit.gpgsign=false --gpg-sign will sign commit' '
86
+ git reset --hard merged &&
87
+ git config commit.gpgsign false &&
88
+ git rebase -fr --gpg-sign -s resolve --root &&
89
+ git verify-commit HEAD
90
+'
91
+
92
test_done