@matheusbsbs / matheus-bagliano / commits / 23cbf11b5c
Fork 0

merge-recursive: porcelain messages for checkout

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) to give better feedback in the case of merge errors. This patch adapts the porcelain messages for the case of checkout instead. This way, when having a checkout error, "merge" no longer appears in the error message. While we're there, we add an advice in the case of would_lose_untracked_file. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Diane Gasselin committed Aug 11, 2010 at 10:38 UTC 23cbf11b5c08c6d0ab0fd0d6f2dc5a32ca31c745
5 files changed +31 -16
builtin/checkout.c
+1 -1
@@ -373,7 +373,7 @@ static int merge_working_tree(struct checkout_opts *opts,
373 topts.src_index = &the_index;
374 topts.dst_index = &the_index;
375
376 - topts.msgs[ERROR_NOT_UPTODATE_FILE] = "You have local changes to '%s'; cannot switch branches.";
376 + set_porcelain_error_msgs(topts.msgs, "checkout");
377
378 refresh_cache(REFRESH_QUIET);
379
builtin/merge.c
+1 -1
@@ -704,7 +704,7 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
704 opts.verbose_update = 1;
705 opts.merge = 1;
706 opts.fn = twoway_merge;
707 - set_porcelain_error_msgs(opts.msgs);
707 + set_porcelain_error_msgs(opts.msgs, "merge");
708
709 trees[nr_trees] = parse_tree_indirect(head);
710 if (!trees[nr_trees++])
merge-recursive.c
+22 -9
@@ -185,7 +185,7 @@ static int git_merge_trees(int index_only,
185 opts.fn = threeway_merge;
186 opts.src_index = &the_index;
187 opts.dst_index = &the_index;
188 - set_porcelain_error_msgs(opts.msgs);
188 + set_porcelain_error_msgs(opts.msgs, "merge");
189
190 init_tree_desc_from_tree(t+0, common);
191 init_tree_desc_from_tree(t+1, head);
@@ -1178,19 +1178,32 @@ static int process_entry(struct merge_options *o,
1178 return clean_merge;
1179 }
1180
1181 -void set_porcelain_error_msgs(const char **msgs)
1181 +void set_porcelain_error_msgs(const char **msgs, const char *cmd)
1182 {
1183 + const char *msg;
1184 + char *tmp;
1185 + const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
1186 if (advice_commit_before_merge)
1184 - msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
1185 - "Your local changes to '%s' would be overwritten by merge. Aborting.\n"
1186 - "Please, commit your changes or stash them before you can merge.";
1187 + msg = "Your local changes to '%%s' would be overwritten by %s. Aborting.\n"
1188 + "Please, commit your changes or stash them before you can %s.";
1189 else
1188 - msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
1189 - "Your local changes to '%s' would be overwritten by merge. Aborting.";
1190 + msg = "Your local changes to '%%s' would be overwritten by %s. Aborting.";
1191 + tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 3);
1192 + sprintf(tmp, msg, cmd, cmd2);
1193 + msgs[ERROR_WOULD_OVERWRITE] = tmp;
1194 + msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
1195 +
1196 msgs[ERROR_NOT_UPTODATE_DIR] =
1197 "Updating '%s' would lose untracked files in it. Aborting.";
1192 - msgs[ERROR_WOULD_LOSE_UNTRACKED] =
1193 - "Untracked working tree file '%s' would be %s by merge. Aborting";
1198 +
1199 + if (advice_commit_before_merge)
1200 + msg = "Untracked working tree file '%%s' would be %%s by %s. Aborting"
1201 + "Please move or remove them before you can %s.";
1202 + else
1203 + msg = "Untracked working tree file '%%s' would be %%s by %s. Aborting";
1204 + tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 3);
1205 + sprintf(tmp, msg, cmd, cmd2);
1206 + msgs[ERROR_WOULD_LOSE_UNTRACKED] = tmp;
1207 }
1208
1209 int merge_trees(struct merge_options *o,
merge-recursive.h
+5 -2
@@ -23,8 +23,11 @@ struct merge_options {
23 struct string_list current_directory_set;
24 };
25
26 -/* Sets the list of user-friendly error messages to be used by merge */
27 -void set_porcelain_error_msgs(const char **msgs);
26 +/*
27 + * Sets the list of user-friendly error messages to be used by the
28 + * command "cmd" (either merge or checkout)
29 + */
30 +void set_porcelain_error_msgs(const char **msgs, const char *cmd);
31
32 /* merge_trees() but with recursive ancestor consolidation */
33 int merge_recursive(struct merge_options *o,
unpack-trees.c
+2 -3
@@ -13,9 +13,8 @@
13 * Error messages expected by scripts out of plumbing commands such as
14 * read-tree. Non-scripted Porcelain is not required to use these messages
15 * and in fact are encouraged to reword them to better suit their particular
16 - * situation better. See how "git checkout" replaces ERROR_NOT_UPTODATE_FILE to
17 - * explain why it does not allow switching between branches when you have
18 - * local changes, for example.
16 + * situation better. See how "git checkout" and "git merge" replaces
17 + * them using set_porcelain_error_msgs(), for example.
18 */
19 const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
20 /* ERROR_WOULD_OVERWRITE */