git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5 v2] merge-recursive: porcelain messages for checkout

From
DGDiane Gasselin <diane.gasselin@ensimag.imag.fr>
Date
Jun 15, 2010, 12:22 UTC
Message-ID
<1276604576-28092-2-git-send-email-diane.gasselin@ensimag.imag.fr>
In-Reply-To
<1276604576-28092-1-git-send-email-diane.gasselin@ensimag.imag.fr>

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@ensimag.imag.fr>
Signed-off-by: Clément Poulain <clement.poulain@ensimag.imag.fr>
Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr>
---
 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
Previous: Diane GasselinNext: Diane Gasselin
Message 2 of 13 in “unpack_trees: nicer error messages”
  1. 0/5 unpack_trees: nicer error messagesDiane Gasselin, Jun 15, 2010
  2. 1/5 merge-recursive: porcelain messages for checkoutDiane Gasselin, Jun 15, 2010
  3. 2/5 unpack_trees: group errors by typeDiane Gasselin, Jun 15, 2010
  4. 3/5 unpack_trees_options: update porcelain messagesDiane Gasselin, Jun 15, 2010
  5. 4/5 tests: update porcelain expected messageDiane Gasselin, Jun 15, 2010
  6. 5/5 t7609: test merge and checkout error messagesDiane Gasselin, Jun 15, 2010
  7. Matthieu MoyJun 15, 2010
  8. Matthieu MoyJun 15, 2010
  9. Matthieu MoyJun 15, 2010
  10. Diane GasselinJun 15, 2010
  11. Matthieu MoyJun 15, 2010
  12. Diane GasselinJun 15, 2010
  13. Matthieu MoyJun 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.