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>

Conrad Irwin committed Aug 20, 2011 at 14:49 UTC 587a9ee7da348f5e6696720d770d0e0da597827c
2 files changed +10 -1
branch.c
+1 -1
@@ -146,7 +146,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
146 if (!ref_exists(ref->buf))
147 return 0;
148 else if (!force)
149 - die("A branch named '%s' already exists.", name);
149 + die("A branch named '%s' already exists.", ref->buf + strlen("refs/heads/"));
150
151 head = resolve_ref("HEAD", sha1, 0, NULL);
152 if (!is_bare_repository() && head && !strcmp(head, ref->buf))
t/t2018-checkout-branch.sh
+9
@@ -118,6 +118,15 @@ test_expect_success 'checkout -b to an existing branch fails' '
118 test_must_fail do_checkout branch2 $HEAD2
119 '
120
121 +test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
122 + git reset --hard HEAD &&
123 + git checkout branch1 &&
124 + git checkout branch2 &&
125 + echo >expect "fatal: A branch named '\''branch1'\'' already exists." &&
126 + test_must_fail git checkout -b @{-1} 2>actual &&
127 + test_cmp expect actual
128 +'
129 +
130 test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
131 git checkout branch1 &&
132