Skip to content

Commit 7488ba3

Browse files
peffgitster
authored andcommitted
merge: handle --verify-signatures for unborn branch
When git-merge sees that we are on an unborn branch (i.e., there is no HEAD), it follows a totally separate code path than the usual merge logic. This code path does not know about verify_signatures, and so we fail to notice bad or missing signatures. This has been broken since --verify-signatures was added in efed002 (merge/pull: verify GPG signatures of commits being merged, 2013-03-31). In an ideal world, we'd unify the flow for this case with the regular merge logic, which would fix this bug and avoid introducing similar ones. But because the unborn case is so different, it would be a burden on the rest of the function to continually handle the missing HEAD. So let's just port the verification check to this special case. Reported-by: Felix Eckhofer <felix@eckhofer.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent edc4d47 commit 7488ba3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/merge.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13341334
die(_("%s - not something we can merge"), argv[0]);
13351335
if (remoteheads->next)
13361336
die(_("Can merge only exactly one commit into empty head"));
1337+
1338+
if (verify_signatures)
1339+
verify_merge_signature(remoteheads->item, verbosity);
1340+
13371341
remote_head_oid = &remoteheads->item->object.oid;
13381342
read_empty(remote_head_oid, 0);
13391343
update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,

t/t7612-merge-verify-signatures.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ test_expect_success GPG 'merge commit with bad signature with merge.verifySignat
103103
git merge --no-verify-signatures $(cat forged.commit)
104104
'
105105

106+
test_expect_success GPG 'merge unsigned commit into unborn branch' '
107+
test_when_finished "git checkout initial" &&
108+
git checkout --orphan unborn &&
109+
test_must_fail git merge --verify-signatures side-unsigned 2>mergeerror &&
110+
test_i18ngrep "does not have a GPG signature" mergeerror
111+
'
112+
106113
test_done

0 commit comments

Comments
 (0)