From: Junio C Hamano Date: Mon, 27 Feb 2012 23:31:50 +0000 (-0800) Subject: Merge branch 'tr/merge-edit-guidance' into maint X-Git-Tag: v1.7.9.3~22 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4eed30a7cb56dfd21917a3685eccb1d8321d852f?hp=-c Merge branch 'tr/merge-edit-guidance' into maint * tr/merge-edit-guidance: merge: add instructions to the commit message when editing --- 4eed30a7cb56dfd21917a3685eccb1d8321d852f diff --combined builtin/merge.c index f385b8ac9e,41d835e3f7..8018a14468 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -48,7 -48,7 +48,7 @@@ static const char * const builtin_merge static int show_diffstat = 1, shortlog_len = -1, squash; static int option_commit = 1, allow_fast_forward = 1; -static int fast_forward_only, option_edit; +static int fast_forward_only, option_edit = -1; static int allow_trivial = 1, have_message; static int overwrite_ignore = 1; static struct strbuf merge_msg = STRBUF_INIT; @@@ -193,7 -193,7 +193,7 @@@ static struct option builtin_merge_opti "create a single commit instead of doing a merge"), OPT_BOOLEAN(0, "commit", &option_commit, "perform a commit if the merge succeeds (default)"), - OPT_BOOLEAN('e', "edit", &option_edit, + OPT_BOOL('e', "edit", &option_edit, "edit message before committing"), OPT_BOOLEAN(0, "ff", &allow_fast_forward, "allow fast-forward (default)"), @@@ -885,11 -885,21 +885,21 @@@ static void abort_commit(const char *er exit(1); } + static const char merge_editor_comment[] = + N_("Please enter a commit message to explain why this merge is necessary,\n" + "especially if it merges an updated upstream into a topic branch.\n" + "\n" + "Lines starting with '#' will be ignored, and an empty message aborts\n" + "the commit.\n"); + static void prepare_to_commit(void) { struct strbuf msg = STRBUF_INIT; + const char *comment = _(merge_editor_comment); strbuf_addbuf(&msg, &merge_msg); strbuf_addch(&msg, '\n'); + if (0 < option_edit) + strbuf_add_lines(&msg, "# ", comment, strlen(comment)); write_merge_msg(&msg); run_hook(get_index_file(), "prepare-commit-msg", git_path("MERGE_MSG"), "merge", NULL, NULL); @@@ -1283,19 -1293,14 +1293,19 @@@ int cmd_merge(int argc, const char **ar sha1_to_hex(commit->object.sha1)); setenv(buf.buf, argv[i], 1); strbuf_reset(&buf); - if (merge_remote_util(commit) && + if (!fast_forward_only && + merge_remote_util(commit) && merge_remote_util(commit)->obj && merge_remote_util(commit)->obj->type == OBJ_TAG) { - option_edit = 1; + if (option_edit < 0) + option_edit = 1; allow_fast_forward = 0; } } + if (option_edit < 0) + option_edit = 0; + if (!use_strategies) { if (!remoteheads->next) add_strategies(pull_twohead, DEFAULT_TWOHEAD);