git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Conrad Irwin <conrad.irwin@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Conrad Irwin <conrad.irwin@gmail.com>
Subject: [PATCH 2/2] Show interpreted branch name in error messages
Date: Sat, 20 Aug 2011 14:49:49 -0700	[thread overview]
Message-ID: <1313876989-16328-3-git-send-email-conrad.irwin@gmail.com> (raw)
In-Reply-To: <1313876989-16328-1-git-send-email-conrad.irwin@gmail.com>

Change the error message when doing: "git branch @{-1}",
"git checkout -b @{-1}", or "git branch -m foo @{-1}"

 * was: A branch named '@{-1}' already exists.
 * now: A branch named 'bar' already exists.

Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com>
---
 branch.c                   |    2 +-
 t/t2018-checkout-branch.sh |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/branch.c b/branch.c
index ff84b5b..1fe3078 100644
--- a/branch.c
+++ b/branch.c
@@ -146,7 +146,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
 	if (!ref_exists(ref->buf))
 		return 0;
 	else if (!force)
-		die("A branch named '%s' already exists.", name);
+		die("A branch named '%s' already exists.", ref->buf + strlen("refs/heads/"));
 
 	head = resolve_ref("HEAD", sha1, 0, NULL);
 	if (!is_bare_repository() && head && !strcmp(head, ref->buf))
diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
index b66db2b..75874e8 100755
--- a/t/t2018-checkout-branch.sh
+++ b/t/t2018-checkout-branch.sh
@@ -118,6 +118,15 @@ test_expect_success 'checkout -b to an existing branch fails' '
 	test_must_fail do_checkout branch2 $HEAD2
 '
 
+test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
+	git reset --hard HEAD &&
+	git checkout branch1 &&
+	git checkout branch2 &&
+	echo  >expect "fatal: A branch named '\''branch1'\'' already exists." &&
+	test_must_fail git checkout -b @{-1} 2>actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
 	git checkout branch1 &&
 
-- 
1.7.6.562.g0b2d4

      parent reply	other threads:[~2011-08-20 21:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-20 21:49 [PATCH] Prevent force updating of the current branch Conrad Irwin
2011-08-20 21:49 ` [PATCH 1/2] Prevent force-updating " Conrad Irwin
2011-08-23 18:20   ` Junio C Hamano
2011-08-23 19:20     ` Conrad Irwin
2011-08-20 21:49 ` Conrad Irwin [this message]

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=1313876989-16328-3-git-send-email-conrad.irwin@gmail.com \
    --to=conrad.irwin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).