From: Junio C Hamano Date: Wed, 9 Dec 2009 06:42:23 +0000 (-0800) Subject: Merge branch 'mm/maint-merge-ff-error-message-fix' into maint X-Git-Tag: v1.6.5.6~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5c30b8f7dd2640a1b75fcbcdd3e175329c5b7bbe?ds=inline;hp=-c Merge branch 'mm/maint-merge-ff-error-message-fix' into maint * mm/maint-merge-ff-error-message-fix: builtin-merge: show user-friendly error messages for fast-forward too. merge-recursive: make the error-message generation an extern function Conflicts: merge-recursive.c --- 5c30b8f7dd2640a1b75fcbcdd3e175329c5b7bbe diff --combined builtin-merge.c index d3eb5092c8,56ecc68239..921453949a --- a/builtin-merge.c +++ b/builtin-merge.c @@@ -70,7 -70,7 +70,7 @@@ static int option_parse_message(const s if (unset) strbuf_setlen(buf, 0); else if (arg) { - strbuf_addf(buf, "%s\n\n", arg); + strbuf_addf(buf, "%s%s", buf->len ? "\n\n" : "", arg); have_message = 1; } else return error("switch `m' requires a value"); @@@ -106,8 -106,8 +106,8 @@@ static struct strategy *get_strategy(co found = 1; if (!found) add_cmdname(¬_strategies, ent->name, ent->len); - exclude_cmds(&main_cmds, ¬_strategies); } + exclude_cmds(&main_cmds, ¬_strategies); } if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) { fprintf(stderr, "Could not find merge strategy '%s'.\n", name); @@@ -650,6 -650,7 +650,7 @@@ static int checkout_fast_forward(unsign opts.verbose_update = 1; opts.merge = 1; opts.fn = twoway_merge; + opts.msgs = get_porcelain_error_msgs(); trees[nr_trees] = parse_tree_indirect(head); if (!trees[nr_trees++]) @@@ -792,7 -793,7 +793,7 @@@ static int suggest_conflicts(void static struct commit *is_old_style_invocation(int argc, const char **argv) { struct commit *second_token = NULL; - if (argc > 1) { + if (argc > 2) { unsigned char second_sha1[20]; if (get_sha1(argv[1], second_sha1)) @@@ -840,6 -841,7 +841,6 @@@ int cmd_merge(int argc, const char **ar const char *best_strategy = NULL, *wt_strategy = NULL; struct commit_list **remotes = &remoteheads; - setup_work_tree(); if (file_exists(git_path("MERGE_HEAD"))) die("You have not concluded your merge. (MERGE_HEAD exists)"); if (read_cache_unmerged()) @@@ -927,13 -929,11 +928,13 @@@ * codepath so we discard the error in this * loop. */ - for (i = 0; i < argc; i++) - merge_name(argv[i], &msg); - fmt_merge_msg(option_log, &msg, &merge_msg); - if (merge_msg.len) - strbuf_setlen(&merge_msg, merge_msg.len-1); + if (!have_message) { + for (i = 0; i < argc; i++) + merge_name(argv[i], &msg); + fmt_merge_msg(option_log, &msg, &merge_msg); + if (merge_msg.len) + strbuf_setlen(&merge_msg, merge_msg.len-1); + } } if (head_invalid || !argc) diff --combined merge-recursive.c index 1870448d98,72bfbaf43a..cd3628c4d9 --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -3,7 -3,6 +3,7 @@@ * Fredrik Kuivinen. * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ +#include "advice.h" #include "cache.h" #include "cache-tree.h" #include "commit.h" @@@ -171,23 -170,6 +171,6 @@@ static int git_merge_trees(int index_on int rc; struct tree_desc t[3]; struct unpack_trees_options opts; - struct unpack_trees_error_msgs msgs = { - /* would_overwrite */ - "Your local changes to '%s' would be overwritten by merge. Aborting.", - /* not_uptodate_file */ - "Your local changes to '%s' would be overwritten by merge. Aborting.", - /* not_uptodate_dir */ - "Updating '%s' would lose untracked files in it. Aborting.", - /* would_lose_untracked */ - "Untracked working tree file '%s' would be %s by merge. Aborting", - /* bind_overlap -- will not happen here */ - NULL, - }; - if (advice_commit_before_merge) { - msgs.would_overwrite = msgs.not_uptodate_file = - "Your local changes to '%s' would be overwritten by merge. Aborting.\n" - "Please, commit your changes or stash them before you can merge."; - } memset(&opts, 0, sizeof(opts)); if (index_only) @@@ -199,7 -181,7 +182,7 @@@ opts.fn = threeway_merge; opts.src_index = &the_index; opts.dst_index = &the_index; - opts.msgs = msgs; + opts.msgs = get_porcelain_error_msgs(); init_tree_desc_from_tree(t+0, common); init_tree_desc_from_tree(t+1, head); @@@ -1186,6 -1168,23 +1169,28 @@@ static int process_entry(struct merge_o return clean_merge; } + struct unpack_trees_error_msgs get_porcelain_error_msgs(void) + { + struct unpack_trees_error_msgs msgs = { + /* would_overwrite */ + "Your local changes to '%s' would be overwritten by merge. Aborting.", + /* not_uptodate_file */ + "Your local changes to '%s' would be overwritten by merge. Aborting.", + /* not_uptodate_dir */ + "Updating '%s' would lose untracked files in it. Aborting.", + /* would_lose_untracked */ + "Untracked working tree file '%s' would be %s by merge. Aborting", + /* bind_overlap -- will not happen here */ + NULL, + }; ++ if (advice_commit_before_merge) { ++ msgs.would_overwrite = msgs.not_uptodate_file = ++ "Your local changes to '%s' would be overwritten by merge. Aborting.\n" ++ "Please, commit your changes or stash them before you can merge."; ++ } + return msgs; + } + int merge_trees(struct merge_options *o, struct tree *head, struct tree *merge,