Skip to content

Commit 6e6ba65

Browse files
committed
Merge branch 'mg/killed-merge'
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 eabdcd4 + 9d89b35 commit 6e6ba65

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
@@ -288,7 +288,10 @@ After seeing a conflict, you can do two things:
288288

289289
* Resolve the conflicts. Git will mark the conflicts in
290290
the working tree. Edit the files into shape and
291-
'git add' them to the index. Use 'git commit' to seal the deal.
291+
'git add' them to the index. Use 'git commit' or
292+
'git merge --continue' to seal the deal. The latter command
293+
checks whether there is a (interrupted) merge in progress
294+
before calling 'git commit'.
292295

293296
You can work through the conflict with a number of tools:
294297

builtin/merge.c

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

762+
static void write_merge_heads(struct commit_list *);
762763
static void prepare_to_commit(struct commit_list *remoteheads)
763764
{
764765
struct strbuf msg = STRBUF_INIT;
765766
strbuf_addbuf(&msg, &merge_msg);
766767
strbuf_addch(&msg, '\n');
768+
if (squash)
769+
BUG("the control must not reach here under --squash");
767770
if (0 < option_edit)
768771
strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
769772
if (signoff)
770773
append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
774+
write_merge_heads(remoteheads);
771775
write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
772776
if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
773777
git_path_merge_msg(), "merge", NULL))
@@ -909,7 +913,7 @@ static int setup_with_upstream(const char ***argv)
909913
return i;
910914
}
911915

912-
static void write_merge_state(struct commit_list *remoteheads)
916+
static void write_merge_heads(struct commit_list *remoteheads)
913917
{
914918
struct commit_list *j;
915919
struct strbuf buf = STRBUF_INIT;
@@ -925,15 +929,20 @@ static void write_merge_state(struct commit_list *remoteheads)
925929
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
926930
}
927931
write_file_buf(git_path_merge_head(), buf.buf, buf.len);
928-
strbuf_addch(&merge_msg, '\n');
929-
write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
930932

931933
strbuf_reset(&buf);
932934
if (fast_forward == FF_NO)
933935
strbuf_addstr(&buf, "no-ff");
934936
write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
935937
}
936938

939+
static void write_merge_state(struct commit_list *remoteheads)
940+
{
941+
write_merge_heads(remoteheads);
942+
strbuf_addch(&merge_msg, '\n');
943+
write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
944+
}
945+
937946
static int default_edit_option(void)
938947
{
939948
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)