]> git.ipfire.org Git - thirdparty/git.git/commit
branch: error copying or renaming a detached HEAD
authorRubén Justo <rjusto@gmail.com>
Tue, 25 Oct 2022 23:01:29 +0000 (01:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2022 17:52:24 +0000 (10:52 -0700)
commit77e7267e47aac247244dc4fb3538baff7463261f
treeea3f2de70696e779b5199927c9e422bce9e62a6e
parentdb29e6bbaed156ae9025ff0474fd788e58230367
branch: error copying or renaming a detached HEAD

In c847f53712 (Detached HEAD (experimental), 2007-01-01) an error
condition was introduced in rename_branch() to prevent renaming, later
also copying, a detached HEAD.

The condition used was checking for NULL in oldname, the source branch
to rename/copy.  That condition cannot be satisfied because if no source
branch is specified, HEAD is going to be used in the call.

The error issued instead is:

fatal: Invalid branch name: 'HEAD'

Let's remove the condition in copy_or_rename_branch() (the current
function name) and check for HEAD before calling it, dying with the
original intended error if we're in a detached HEAD.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
t/t3200-branch.sh