Skip to content

Commit 78ad094

Browse files
committed
Merge branch 'mg/killed-merge' into maint
Killing "git merge --edit" before the editor returns control left the repository in a state with MERGE_MSG but without MERGE_HEAD, which incorrectly tells the subsequent "git commit" that there was a squash merge in progress. This has been fixed. * mg/killed-merge: merge: save merge state earlier merge: split write_merge_state in two merge: clarify call chain Documentation/git-merge: explain --continue
2 parents 648a50a + 9d89b35 commit 78ad094

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Documentation/git-merge.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ After seeing a conflict, you can do two things:
280280

281281
* Resolve the conflicts. Git will mark the conflicts in
282282
the working tree. Edit the files into shape and
283-
'git add' them to the index. Use 'git commit' to seal the deal.
283+
'git add' them to the index. Use 'git commit' or
284+
'git merge --continue' to seal the deal. The latter command
285+
checks whether there is a (interrupted) merge in progress
286+
before calling 'git commit'.
284287

285288
You can work through the conflict with a number of tools:
286289

builtin/merge.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,17 @@ N_("Please enter a commit message to explain why this merge is necessary,\n"
756756
"Lines starting with '%c' will be ignored, and an empty message aborts\n"
757757
"the commit.\n");
758758

759+
static void write_merge_heads(struct commit_list *);
759760
static void prepare_to_commit(struct commit_list *remoteheads)
760761
{
761762
struct strbuf msg = STRBUF_INIT;
762763
strbuf_addbuf(&msg, &merge_msg);
763764
strbuf_addch(&msg, '\n');
765+
if (squash)
766+
BUG("the control must not reach here under --squash");
764767
if (0 < option_edit)
765768
strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
769+
write_merge_heads(remoteheads);
766770
write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
767771
if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
768772
git_path_merge_msg(), "merge", NULL))
@@ -904,7 +908,7 @@ static int setup_with_upstream(const char ***argv)
904908
return i;
905909
}
906910

907-
static void write_merge_state(struct commit_list *remoteheads)
911+
static void write_merge_heads(struct commit_list *remoteheads)
908912
{
909913
struct commit_list *j;
910914
struct strbuf buf = STRBUF_INIT;
@@ -920,15 +924,20 @@ static void write_merge_state(struct commit_list *remoteheads)
920924
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
921925
}
922926
write_file_buf(git_path_merge_head(), buf.buf, buf.len);
923-
strbuf_addch(&merge_msg, '\n');
924-
write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
925927

926928
strbuf_reset(&buf);
927929
if (fast_forward == FF_NO)
928930
strbuf_addstr(&buf, "no-ff");
929931
write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
930932
}
931933

934+
static void write_merge_state(struct commit_list *remoteheads)
935+
{
936+
write_merge_heads(remoteheads);
937+
strbuf_addch(&merge_msg, '\n');
938+
write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
939+
}
940+
932941
static int default_edit_option(void)
933942
{
934943
static const char name[] = "GIT_MERGE_AUTOEDIT";

t/t7600-merge.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,4 +774,19 @@ test_expect_success 'merge can be completed with --continue' '
774774
verify_parents $c0 $c1
775775
'
776776

777+
write_script .git/FAKE_EDITOR <<EOF
778+
# kill -TERM command added below.
779+
EOF
780+
781+
test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
782+
git reset --hard c0 &&
783+
! "$SHELL_PATH" -c '\''
784+
echo kill -TERM $$ >> .git/FAKE_EDITOR
785+
GIT_EDITOR=.git/FAKE_EDITOR
786+
export GIT_EDITOR
787+
exec git merge --no-ff --edit c1'\'' &&
788+
git merge --continue &&
789+
verify_parents $c0 $c1
790+
'
791+
777792
test_done

0 commit comments

Comments
 (0)