From e2de82f27128441278da979ef101239c40188064 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Mon, 21 Aug 2017 14:53:14 +0200 Subject: Documentation/git-merge: explain --continue Currently, 'git merge --continue' is mentioned but not explained. Explain it. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 04fdd8c..f90faf7 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -280,7 +280,10 @@ After seeing a conflict, you can do two things: * Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and - 'git add' them to the index. Use 'git commit' to seal the deal. + 'git add' them to the index. Use 'git commit' or + 'git merge --continue' to seal the deal. The latter command + checks whether there is a (interrupted) merge in progress + before calling 'git commit'. You can work through the conflict with a number of tools: -- cgit v0.10.2-6-g49f6 From 62dc42b9370b123924ba3423d51976e78d13a924 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 23 Aug 2017 14:10:43 +0200 Subject: merge: clarify call chain prepare_to_commit() cannot be reached in the non-squash case: It is called by merge_trivial() and finish_automerge() only, but the calls to the latter are somewhat hard to track: If option_commit is not set, the code in cmd_merge() uses a fake conflict return code (ret=1) to avoid writing the tree, which also avoids setting automerge_was_ok (just as in the proper ret==1 case), so that finish_automerge() is not called. To ensure that no code change breaks that assumption, safe-guard prepare_to_commit() by a BUG() statement. Suggested-by: Junio C Hamano Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/builtin/merge.c b/builtin/merge.c index 900bafd..2d79e79 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -761,6 +761,8 @@ static void prepare_to_commit(struct commit_list *remoteheads) struct strbuf msg = STRBUF_INIT; strbuf_addbuf(&msg, &merge_msg); strbuf_addch(&msg, '\n'); + if (squash) + BUG("the control must not reach here under --squash"); if (0 < option_edit) strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char); write_file_buf(git_path_merge_msg(), msg.buf, msg.len); -- cgit v0.10.2-6-g49f6 From 8e6a6bb36037da87ac98da280459269168b9f525 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 23 Aug 2017 14:10:44 +0200 Subject: merge: split write_merge_state in two write_merge_state() writes out the merge heads, mode, and msg. But we may want to write out heads, mode without the msg. So, split out heads (+mode) into a separate function write_merge_heads() that is called by write_merge_state(). No funtional change so far, except when these non-atomic writes are interrupted: we write heads-mode-msg now when we used to write heads-msg-mode. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/builtin/merge.c b/builtin/merge.c index 2d79e79..f239fd5 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -906,7 +906,7 @@ static int setup_with_upstream(const char ***argv) return i; } -static void write_merge_state(struct commit_list *remoteheads) +static void write_merge_heads(struct commit_list *remoteheads) { struct commit_list *j; struct strbuf buf = STRBUF_INIT; @@ -922,8 +922,6 @@ static void write_merge_state(struct commit_list *remoteheads) strbuf_addf(&buf, "%s\n", oid_to_hex(oid)); } write_file_buf(git_path_merge_head(), buf.buf, buf.len); - strbuf_addch(&merge_msg, '\n'); - write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len); strbuf_reset(&buf); if (fast_forward == FF_NO) @@ -931,6 +929,13 @@ static void write_merge_state(struct commit_list *remoteheads) write_file_buf(git_path_merge_mode(), buf.buf, buf.len); } +static void write_merge_state(struct commit_list *remoteheads) +{ + write_merge_heads(remoteheads); + strbuf_addch(&merge_msg, '\n'); + write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len); +} + static int default_edit_option(void) { static const char name[] = "GIT_MERGE_AUTOEDIT"; -- cgit v0.10.2-6-g49f6 From 9d89b35526b54c3ba33371b184a1ba6e30f8f46f Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 23 Aug 2017 14:10:45 +0200 Subject: merge: save merge state earlier 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 Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/builtin/merge.c b/builtin/merge.c index f239fd5..08a4083 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -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)) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 2ebda50..80194b7 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 <> .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 -- cgit v0.10.2-6-g49f6