Skip to content

Commit 03d3aad

Browse files
committed
Fix branch -m @{-1} newname
The command is supposed to rename the branch we were on before switched from to a new name, but was not aware of the short-hand notation we added recently. Signed-off-by: Junio C Hamano <[email protected]>
1 parent a31dca0 commit 03d3aad

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin-branch.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,18 @@ static void rename_branch(const char *oldname, const char *newname, int force)
468468
if (!oldname)
469469
die("cannot rename the current branch while not on any.");
470470

471-
strbuf_addf(&oldref, "refs/heads/%s", oldname);
472-
471+
strbuf_branchname(&oldref, oldname);
472+
strbuf_splice(&oldref, 0, 0, "refs/heads/", 11);
473473
if (check_ref_format(oldref.buf))
474-
die("Invalid branch name: %s", oldref.buf);
475-
476-
strbuf_addf(&newref, "refs/heads/%s", newname);
474+
die("Invalid branch name: '%s'", oldname);
477475

476+
strbuf_branchname(&newref, newname);
477+
strbuf_splice(&newref, 0, 0, "refs/heads/", 11);
478478
if (check_ref_format(newref.buf))
479-
die("Invalid branch name: %s", newref.buf);
479+
die("Invalid branch name: '%s'", newname);
480480

481481
if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
482-
die("A branch named '%s' already exists.", newname);
482+
die("A branch named '%s' already exists.", newref.buf + 11);
483483

484484
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
485485
oldref.buf, newref.buf);

0 commit comments

Comments
 (0)