merge: save merge state earlier
authorMichael J Gruber <git@grubix.eu>
Wed, 23 Aug 2017 12:10:45 +0000 (14:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 17:35:02 +0000 (10:35 -0700)
If the `git merge` process is killed while waiting for the editor to
finish, the merge state is lost but the prepared merge msg and tree is kept.
So, a subsequent `git commit` creates a squashed merge even when the
user asked for proper merge commit originally.

Demonstrate the problem with a test crafted after the in t7502. The test
requires EXECKEEPSPID (thus does not run under MINGW).

Save the merge state earlier (in the non-squash case) so that it does
not get lost. This makes the test pass.

Reported-by: hIpPy <hippy2981@gmail.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c
t/t7600-merge.sh
index f239fd55efd3167aff9c06214184884b22177769..08a4083b6de51954b545028003c303e4df9e3127 100644 (file)
@@ -756,6 +756,7 @@ N_("Please enter a commit message to explain why this merge is necessary,\n"
    "Lines starting with '%c' will be ignored, and an empty message aborts\n"
    "the commit.\n");
 
+static void write_merge_heads(struct commit_list *);
 static void prepare_to_commit(struct commit_list *remoteheads)
 {
        struct strbuf msg = STRBUF_INIT;
@@ -765,6 +766,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
                BUG("the control must not reach here under --squash");
        if (0 < option_edit)
                strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
+       write_merge_heads(remoteheads);
        write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
        if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
                            git_path_merge_msg(), "merge", NULL))
index 2ebda509ac337f99c7ab5651734a5b20d4a0b6f4..80194b79f90c800e7aaeecca9cd502e3ade494b4 100755 (executable)
@@ -774,4 +774,19 @@ test_expect_success 'merge can be completed with --continue' '
        verify_parents $c0 $c1
 '
 
+write_script .git/FAKE_EDITOR <<EOF
+# kill -TERM command added below.
+EOF
+
+test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
+       git reset --hard c0 &&
+       ! "$SHELL_PATH" -c '\''
+         echo kill -TERM $$ >> .git/FAKE_EDITOR
+         GIT_EDITOR=.git/FAKE_EDITOR
+         export GIT_EDITOR
+         exec git merge --no-ff --edit c1'\'' &&
+       git merge --continue &&
+       verify_parents $c0 $c1
+'
+
 test_done