From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] checkout: warn users if action is taken in ambiguous situation
Date: Fri, 31 Aug 2012 21:38:54 +0700 [thread overview]
Message-ID: <1346423934-7003-1-git-send-email-pclouds@gmail.com> (raw)
"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
next reply other threads:[~2012-08-31 14:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-31 14:38 Nguyễn Thái Ngọc Duy [this message]
2012-08-31 18:27 ` [PATCH] checkout: warn users if action is taken in ambiguous situation Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346423934-7003-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).