git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkout: Better error message on invalid branch name
@ 2010-06-21 18:53 Ævar Arnfjörð Bjarmason
  2010-06-21 20:58 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-06-21 18:53 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason

Change the error message for `git checkout -b "I LOVE YOU"' and other
invalid branch names to say what branch names are invalid, rather than
just saying we don't like it.

Before:

    $ git checkout -b "I LOVE YOU"
    fatal: git checkout: we do not like 'I LOVE YOU' as a branch name.

After:

    $ git checkout -b "I LOVE YOU"
    fatal: git checkout: The name "I LOVE YOU" is not a valid Git branch name.
    A branch name can not:
        - Have a path component that begins with "."
        - Have a double dot ".."
        - Have an ASCII control character, "~", "^", ":" or SP, anywhere
        - End with a "/"
        - End with ".lock"
        - Contain a "\" (backslash

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

Git didn't like my branch name, but I didn't like its error
message. Here's a fix for it.

 builtin/checkout.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1994be9..fec8335 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -856,7 +856,15 @@ no_reference:
 	if (opts.new_branch) {
 		struct strbuf buf = STRBUF_INIT;
 		if (strbuf_check_branch_ref(&buf, opts.new_branch))
-			die("git checkout: we do not like '%s' as a branch name.",
+			die("git checkout: The name \"%s\" is not a valid branch name.\n"
+			    "A branch name can not:\n"
+			    /* From the comment for bad_ref_char in refs.c */
+			    "    - Have a path component that begins with \".\"\n"
+			    "    - Have a double dot \"..\"\n"
+			    "    - Have an ASCII control character, \"~\", \"^\", \":\" or SP, anywhere\n"
+			    "    - End with a \"/\"\n"
+			    "    - End with \".lock\"\n"
+			    "    - Contain a \"\\\" (backslash)",
 			    opts.new_branch);
 		if (!get_sha1(buf.buf, rev))
 			die("git checkout: branch %s already exists", opts.new_branch);
-- 
1.7.1.251.g92a7

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

* Re: [PATCH] checkout: Better error message on invalid branch name
  2010-06-21 18:53 [PATCH] checkout: Better error message on invalid branch name Ævar Arnfjörð Bjarmason
@ 2010-06-21 20:58 ` Junio C Hamano
  2010-06-21 21:09   ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2010-06-21 20:58 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> Change the error message for `git checkout -b "I LOVE YOU"' and other
> invalid branch names to say what branch names are invalid, rather than
> just saying we don't like it.
>
> Before:
>
>     $ git checkout -b "I LOVE YOU"
>     fatal: git checkout: we do not like 'I LOVE YOU' as a branch name.
>
> After:
>
>     $ git checkout -b "I LOVE YOU"
>     fatal: git checkout: The name "I LOVE YOU" is not a valid Git branch name.
>     A branch name can not:
>         - Have a path component that begins with "."
>         - Have a double dot ".."
>         - Have an ASCII control character, "~", "^", ":" or SP, anywhere
>         - End with a "/"
>         - End with ".lock"
>         - Contain a "\" (backslash

Cluttering the output without protecting it with "advice" does not look
like a "fix" nor improvement.

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

* Re: [PATCH] checkout: Better error message on invalid branch name
  2010-06-21 20:58 ` Junio C Hamano
@ 2010-06-21 21:09   ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-06-21 21:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Jun 21, 2010 at 20:58, Junio C Hamano <gitster@pobox.com> wrote:
> Cluttering the output without protecting it with "advice" does not look
> like a "fix" nor improvement.

The short version of the message would also need to be fixed then, to
do that properly would require bigger changes in the return code of
bad_ref_char and the functions that call it. Then we could have e.g.:

    $ git checkout -b "I LOVE YOU"
    fatal: git checkout: Branch name cannot contain ' ';  marked by
<-- HERE in 'I ' <-- HERE

Similar to what you get from:

    $ perl -e '/I LOVE [/'

That would also make the long version unnecessary, and maybe improve
some other error messages that deal with ref names.

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

end of thread, other threads:[~2010-06-21 21:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-21 18:53 [PATCH] checkout: Better error message on invalid branch name Ævar Arnfjörð Bjarmason
2010-06-21 20:58 ` Junio C Hamano
2010-06-21 21:09   ` Ævar Arnfjörð Bjarmason

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).