From: Junio C Hamano Date: Sun, 10 Sep 2017 08:02:55 +0000 (+0900) Subject: Merge branch 'mg/killed-merge' into maint X-Git-Tag: v2.14.2~24 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/78ad09403c0c87ae52573bbac2fa7e093152891d?hp=-c 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 --- 78ad09403c0c87ae52573bbac2fa7e093152891d diff --combined builtin/merge.c index d5797b8fe7,08a4083b6d..6150571a56 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -537,7 -537,7 +537,7 @@@ static void parse_branch_merge_options( die(_("Bad branch.%s.mergeoptions string: %s"), branch, split_cmdline_strerror(argc)); REALLOC_ARRAY(argv, argc + 2); - memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); + MOVE_ARRAY(argv + 1, argv, argc + 1); argc++; argv[0] = "branch.*.mergeoptions"; parse_options(argc, argv, NULL, builtin_merge_options, @@@ -756,13 -756,17 +756,17 @@@ N_("Please enter a commit message to ex "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); + 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)) @@@ -904,7 -908,7 +908,7 @@@ static int setup_with_upstream(const ch 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; @@@ -920,8 -924,6 +924,6 @@@ 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) @@@ -929,6 -931,13 +931,13 @@@ 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";