git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkout: warn users if action is taken in ambiguous situation
@ 2012-08-31 14:38 Nguyễn Thái Ngọc Duy
  2012-08-31 18:27 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-08-31 14:38 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

"git checkout foo" (no more arguments) always checks out existing
branch "foo" even if "foo" exists on working directory. To avoid
confusion to users who do not know this exception, say something along
the action.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Personally I disagree with the comment above the top chunk about
 stopping annoying users in this case. I think the annoyance is a good
 sign for them to rename their branches to something more sensible.

 builtin/checkout.c |  6 ++++--
 cache.h            |  2 ++
 setup.c            | 21 +++++++++++++++++----
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 7d922c6..7bc4e8a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,8 +899,10 @@ static int parse_branchname_arg(int argc, const char **argv,
 		 * even if there happen to be a file called 'branch';
 		 * it would be extremely annoying.
 		 */
-		if (argc)
-			verify_non_filename(NULL, arg);
+		const char *action = NULL;
+		if (!argc)
+			action = _("Checked out the new branch.");
+		verify_non_filename_gently(NULL, arg, action);
 	} else {
 		argcount++;
 		argv++;
diff --git a/cache.h b/cache.h
index 95daa69..95f11df 100644
--- a/cache.h
+++ b/cache.h
@@ -404,6 +404,8 @@ extern void verify_filename(const char *prefix,
 			    const char *name,
 			    int diagnose_misspelt_rev);
 extern void verify_non_filename(const char *prefix, const char *name);
+extern void verify_non_filename_gently(const char *prefix, const char *name,
+				       const char *preferred_action);
 extern int path_inside_repo(const char *prefix, const char *path);
 
 #define INIT_DB_QUIET 0x0001
diff --git a/setup.c b/setup.c
index 3a1b2fd..4b776cf 100644
--- a/setup.c
+++ b/setup.c
@@ -133,7 +133,8 @@ void verify_filename(const char *prefix,
  * and we parsed the arg as a refname.  It should not be interpretable
  * as a filename.
  */
-void verify_non_filename(const char *prefix, const char *arg)
+void verify_non_filename_gently(const char *prefix, const char *arg,
+				const char *preferred_action)
 {
 	if (!is_inside_work_tree() || is_inside_git_dir())
 		return;
@@ -141,9 +142,21 @@ void verify_non_filename(const char *prefix, const char *arg)
 		return; /* flag */
 	if (!check_filename(prefix, arg))
 		return;
-	die("ambiguous argument '%s': both revision and filename\n"
-	    "Use '--' to separate paths from revisions, like this:\n"
-	    "'git <command> [<revision>...] -- [<file>...]'", arg);
+	if (!preferred_action)
+		die(_("ambiguous argument '%s': both revision and filename\n"
+		      "Use '--' to separate paths from revisions, like this:\n"
+		      "'git <command> [<revision>...] -- [<file>...]'"), arg);
+	else {
+		warning(_("ambiguous argument '%s': both revision and filename\n"
+			  "Use '--' to separate paths from revisions, like this:\n"
+			  "'git <command> [<revision>...] -- [<file>...]'"), arg);
+		warning("%s", preferred_action);
+	}
+}
+
+void verify_non_filename(const char *prefix, const char *arg)
+{
+	verify_non_filename_gently(prefix, arg, NULL);
 }
 
 /*
-- 
1.7.12.rc2.18.g61b472e

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-31 18:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-31 14:38 [PATCH] checkout: warn users if action is taken in ambiguous situation Nguyễn Thái Ngọc Duy
2012-08-31 18:27 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).