Merge branch 'mg/killed-merge' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:02:55 +0000 (17:02 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:02:55 +0000 (17:02 +0900)
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

1  2 
builtin/merge.c
diff --combined builtin/merge.c
index d5797b8fe77c99c89323348f3a0bd1d68ae9b453,08a4083b6de51954b545028003c303e4df9e3127..6150571a56f3996986cc204fd79e86260c02bad7
@@@ -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;
                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)
        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";