From 587a9ee7da348f5e6696720d770d0e0da597827c Mon Sep 17 00:00:00 2001
From: Conrad Irwin <conrad.irwin@gmail.com>
Date: Sat, 20 Aug 2011 14:49:49 -0700
Subject: [PATCH] Show interpreted branch name in error messages

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 branch.c                   | 2 +-
 t/t2018-checkout-branch.sh | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/branch.c b/branch.c
index ff84b5b9b7..1fe3078a6c 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 b66db2b881..75874e85df 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 &&
 
-- 
2.48.1