git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 4/4] merge: save merge state earlier

From
Michael J Gruber <git@grubix.eu>
Date
Aug 23, 2017, 12:10 UTC
Message-ID
<3daa548a93e8e3166ef434deacf71b218f3c9263.1503489842.git.git@grubix.eu>
In-Reply-To
<xmqq1so34m6d.fsf@gitster.mtv.corp.google.com>

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>
---
 builtin/merge.c  |  2 ++
 t/t7600-merge.sh | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
diff --git a/builtin/merge.c b/builtin/merge.c
index db3335b3bf..2d5c45a904 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -758,6 +758,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;
@@ -769,6 +770,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
 	if (signoff)
 		append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
+	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))
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 2ebda509ac..80194b79f9 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -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
-- 
2.14.1.426.g4352aa77a5
Previous: Michael J GruberNext: Junio C Hamano
Message 14 of 22 in “Git makes a merge commit but as a normal (non-merge) commit”
  1. hIpPyAug 18, 2017
  2. Michael J GruberAug 21, 2017
  3. merge: save merge state earlierMichael J Gruber, Aug 21, 2017
  4. 1/3 Documentation/git-merge: explain --continueMichael J Gruber, Aug 21, 2017
  5. Martin ÅgrenAug 21, 2017
  6. Michael J GruberAug 22, 2017
  7. Martin ÅgrenAug 22, 2017
  8. hIpPyAug 22, 2017
  9. Junio C HamanoAug 22, 2017
  10. 1/4 Documentation/git-merge: explain --continueMichael J Gruber, Aug 23, 2017
  11. 0/4 Keep merge during killsMichael J Gruber, Aug 23, 2017
  12. 2/4 merge: clarify call chainMichael J Gruber, Aug 23, 2017
  13. 3/4 merge: split write_merge_state in twoMichael J Gruber, Aug 23, 2017
  14. 4/4 merge: save merge state earlierMichael J Gruber, Aug 23, 2017
  15. Junio C HamanoAug 22, 2017
  16. 3/3 merge: save merge state earlierMichael J Gruber, Aug 21, 2017
  17. Junio C HamanoAug 22, 2017
  18. Michael J GruberAug 22, 2017
  19. Junio C HamanoAug 22, 2017
  20. 0/3 Keep merge during killsMichael J Gruber, Aug 21, 2017
  21. 2/3 merge: split write_merge_state in twoMichael J Gruber, Aug 21, 2017
  22. Junio C HamanoAug 22, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.