A porcelain message was first added in checkout.c in the commit 8ccba008 (Junio C Hamano, Sat May 17 21:03:49 2008, unpack-trees: allow Porcelain to give different error messages) so that it better fit the situation. This patch proposes other specific porcelain messages for checkout instead of using merge plumbing error messages. This way, when having a checkout error, "merge" no longer appears in the error message. Signed-off-by: Diane Gasselin <diane.gasselin@xxxxxxxxxxxxxxx> Signed-off-by: Clément Poulain <clement.poulain@xxxxxxxxxxxxxxx> Signed-off-by: Axel Bonnet <axel.bonnet@xxxxxxxxxxxxxxx> --- builtin/checkout.c | 1 + builtin/merge.c | 3 ++- merge-recursive.c | 48 +++++++++++++++++++++++++++++++----------------- merge-recursive.h | 6 ++++-- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 88b1f43..6f34566 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -372,6 +372,7 @@ static int merge_working_tree(struct checkout_opts *opts, topts.src_index = &the_index; topts.dst_index = &the_index; + topts.msgs = get_porcelain_error_msgs("checkout"); topts.msgs.not_uptodate_file = "You have local changes to '%s'; cannot switch branches."; refresh_cache(REFRESH_QUIET); diff --git a/builtin/merge.c b/builtin/merge.c index 37d414b..501177f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -704,7 +704,8 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote opts.verbose_update = 1; opts.merge = 1; opts.fn = twoway_merge; - opts.msgs = get_porcelain_error_msgs(); + + opts.msgs = get_porcelain_error_msgs("merge"); trees[nr_trees] = parse_tree_indirect(head); if (!trees[nr_trees++]) diff --git a/merge-recursive.c b/merge-recursive.c index 206c103..80c9744 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -185,7 +185,7 @@ static int git_merge_trees(int index_only, opts.fn = threeway_merge; opts.src_index = &the_index; opts.dst_index = &the_index; - opts.msgs = get_porcelain_error_msgs(); + opts.msgs = get_porcelain_error_msgs("merge"); init_tree_desc_from_tree(t+0, common); init_tree_desc_from_tree(t+1, head); @@ -1178,24 +1178,38 @@ static int process_entry(struct merge_options *o, return clean_merge; } -struct unpack_trees_error_msgs get_porcelain_error_msgs(void) +struct unpack_trees_error_msgs get_porcelain_error_msgs(const char *cmd) { - 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, - }; + struct unpack_trees_error_msgs msgs; + + /* would_overwrite */ + msgs.would_overwrite = malloc(sizeof(char) * 72); + sprintf((char *)msgs.would_overwrite, + "Your local changes to '%%s' would be overwritten by %s. Aborting.", + cmd); + /* not_uptodate_file */ + msgs.not_uptodate_file = msgs.would_overwrite; + /* not_uptodate_dir */ + msgs.not_uptodate_dir = + "Updating '%s' would lose untracked files in it. Aborting."; + /* would_lose_untracked */ + msgs.would_lose_untracked = malloc(sizeof(char) * 72); + sprintf((char *)msgs.would_lose_untracked, + "Untracked working tree file '%%s' would be %%s by %s. Aborting.", + cmd); + 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."; + msgs.would_overwrite = malloc(sizeof(char) * 140); + sprintf((char *)msgs.would_overwrite, + "Your local changes to '%%s' would be overwritten by %s. Aborting.\n" + "Please, commit your changes or stash them before you can %s.", + cmd, strcmp(cmd,"checkout") ? cmd : "swicth branches"); + msgs.not_uptodate_file = msgs.would_overwrite; + msgs.would_lose_untracked = malloc (sizeof(char) * 135); + sprintf((char *)msgs.would_lose_untracked, + "Untracked working tree file '%%s' would be %%s by %s. Aborting.\n" + "Please move or remove them before you can %s.", + cmd, strcmp(cmd,"checkout") ? cmd : "swicth branches"); } return msgs; } diff --git a/merge-recursive.h b/merge-recursive.h index 0cc465e..d910ae6 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -23,8 +23,10 @@ struct merge_options { struct string_list current_directory_set; }; -/* Return a list of user-friendly error messages to be used by merge */ -struct unpack_trees_error_msgs get_porcelain_error_msgs(void); +/* Return a list of user-friendly error messages to be used by + * the command cmd which would be either merge or checkout + */ +struct unpack_trees_error_msgs get_porcelain_error_msgs(const char *cmd); /* merge_trees() but with recursive ancestor consolidation */ int merge_recursive(struct merge_options *o, -- 1.6.6.7.ga5fe3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html