summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-08-26 22:55:10 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-26 22:55:10 -0700
commit6e6ba65a7c8f8f9556ec42678f661794d47f7f98 (patch)
tree3a9714f9a2794a1511d974b79d20e124f2ef6a7d
parenteabdcd4ab4b04af8f39e5ea3847b6d364acb874e (diff)
parent9d89b35526b54c3ba33371b184a1ba6e30f8f46f (diff)
downloadgit-6e6ba65a7c8f8f9556ec42678f661794d47f7f98.tar.gz
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
-rw-r--r--Documentation/git-merge.txt5
-rw-r--r--builtin/merge.c15
-rwxr-xr-xt/t7600-merge.sh15
3 files changed, 31 insertions, 4 deletions
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 6b308ab6d0..615e6bacde 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -288,7 +288,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:
diff --git a/builtin/merge.c b/builtin/merge.c
index 7b7320dede..7df3fe3927 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -759,15 +759,19 @@ 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;
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);
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))
@@ -909,7 +913,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;
@@ -925,8 +929,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)
@@ -934,6 +936,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";
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