branch: fix "copy" to never touch HEAD

When creating a new branch B by copying the branch A that happens to
be the current branch, it also updates HEAD to point at the new
branch.  It probably was made this way because "git branch -c A B"
piggybacked its implementation on "git branch -m A B",

This does not match the usual expectation.  If I were sitting on a
blue chair, and somebody comes and repaints it to red, I would
accept ending up sitting on a chair that is now red (I am also OK to
stand, instead, as there no longer is my favourite blue chair).  But
if somebody creates a new red chair, modelling it after the blue
chair I am sitting on, I do not expect to be booted off of the blue
chair and ending up on sitting on the new red one.

Let's fix this before it hits 'next'.  Those who want to create a
new branch and switch to it can do "git checkout B" after doing a
"git branch -c B", and if that operation is so useful and deserves a
short-hand way to do so, perhaps extend "git checkout -b B" to copy
configurations while creating the new branch B.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2017-09-22 12:24:50 +09:00
parent 52d59cc645
commit e5435ff1fc
2 changed files with 8 additions and 11 deletions

View File

@ -506,12 +506,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
oldref.buf + 11);
}
if (replace_each_worktree_head_symref(oldref.buf, newref.buf, logmsg.buf)) {
if (copy)
die(_("Branch copied to %s, but HEAD is not updated!"), newname);
else
die(_("Branch renamed to %s, but HEAD is not updated!"), newname);
}
if (!copy &&
replace_each_worktree_head_symref(oldref.buf, newref.buf, logmsg.buf))
die(_("Branch renamed to %s, but HEAD is not updated!"), newname);
strbuf_release(&logmsg);