From: Junio C Hamano Date: Wed, 19 Oct 2011 17:49:27 +0000 (-0700) Subject: Merge branch 'js/merge-edit-option' X-Git-Tag: v1.7.8-rc0~36 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3dfbe68fc29248feea3a384e156497ca2463f932;p=git.git Merge branch 'js/merge-edit-option' * js/merge-edit-option: Teach merge the '[-e|--edit]' option Conflicts: builtin/merge.c --- 3dfbe68fc29248feea3a384e156497ca2463f932 diff --cc builtin/merge.c index 7d593097d,a8dbf4a32..dffd5ec12 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -861,15 -852,39 +863,39 @@@ static void read_merge_msg(struct strbu die_errno(_("Could not read from '%s'"), git_path("MERGE_MSG")); } - static void run_prepare_commit_msg(void) + static void write_merge_state(void); + static void abort_commit(const char *err_msg) { - write_merge_msg(); + if (err_msg) + error("%s", err_msg); + fprintf(stderr, + _("Not committing merge; use 'git commit' to complete the merge.\n")); + write_merge_state(); + exit(1); + } + + static void prepare_to_commit(void) + { + struct strbuf msg = STRBUF_INIT; + strbuf_addbuf(&msg, &merge_msg); + strbuf_addch(&msg, '\n'); + write_merge_msg(&msg); run_hook(get_index_file(), "prepare-commit-msg", git_path("MERGE_MSG"), "merge", NULL, NULL); - read_merge_msg(); + if (option_edit) { + if (launch_editor(git_path("MERGE_MSG"), NULL, NULL)) + abort_commit(NULL); + } + read_merge_msg(&msg); + stripspace(&msg, option_edit); + if (!msg.len) + abort_commit(_("Empty commit message.")); + strbuf_release(&merge_msg); + strbuf_addbuf(&merge_msg, &msg); + strbuf_release(&msg); } -static int merge_trivial(void) +static int merge_trivial(struct commit *head) { unsigned char result_tree[20], result_commit[20]; struct commit_list *parent = xmalloc(sizeof(*parent)); @@@ -880,9 -895,9 +906,9 @@@ parent->next = xmalloc(sizeof(*parent->next)); parent->next->item = remoteheads->item; parent->next->next = NULL; - run_prepare_commit_msg(); + prepare_to_commit(); commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL); - finish(result_commit, "In-index merge"); + finish(head, result_commit, "In-index merge"); drop_save(); return 0; } @@@ -909,12 -923,12 +935,12 @@@ static int finish_automerge(struct comm for (j = remoteheads; j; j = j->next) pptr = &commit_list_insert(j->item, pptr)->next; } - free_commit_list(remoteheads); strbuf_addch(&merge_msg, '\n'); - run_prepare_commit_msg(); + prepare_to_commit(); + free_commit_list(remoteheads); commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); - finish(result_commit, buf.buf); + finish(head, result_commit, buf.buf); strbuf_release(&buf); drop_save(); return 0; @@@ -1422,34 -1464,9 +1478,9 @@@ int cmd_merge(int argc, const char **ar } if (squash) - finish(NULL, NULL); + finish(head_commit, NULL, NULL); - else { - int fd; - struct commit_list *j; - - for (j = remoteheads; j; j = j->next) - strbuf_addf(&buf, "%s\n", - sha1_to_hex(j->item->object.sha1)); - fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666); - if (fd < 0) - die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_HEAD")); - if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die_errno(_("Could not write to '%s'"), git_path("MERGE_HEAD")); - close(fd); - strbuf_addch(&merge_msg, '\n'); - write_merge_msg(); - fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) - die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_MODE")); - strbuf_reset(&buf); - if (!allow_fast_forward) - strbuf_addf(&buf, "no-ff"); - if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die_errno(_("Could not write to '%s'"), git_path("MERGE_MODE")); - close(fd); - } + else + write_merge_state(); if (merge_was_ok) { fprintf(stderr, _("Automatic merge went well; "