diff options
author | Rubén Justo <rjusto@gmail.com> | 2022-10-26 01:01:29 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-10-26 19:52:24 +0200 |
commit | 77e7267e47aac247244dc4fb3538baff7463261f (patch) | |
tree | ea3f2de70696e779b5199927c9e422bce9e62a6e /t | |
parent | Sync with 'maint' (diff) | |
download | git-77e7267e47aac247244dc4fb3538baff7463261f.tar.xz git-77e7267e47aac247244dc4fb3538baff7463261f.zip |
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>
Diffstat (limited to 't')
-rwxr-xr-x | t/t3200-branch.sh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 7d8edff9c3..38c57de71b 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -268,6 +268,17 @@ test_expect_success 'git branch -M topic topic should work when main is checked git branch -M topic topic ' +test_expect_success 'git branch -M and -C fail on detached HEAD' ' + git checkout HEAD^{} && + test_when_finished git checkout - && + echo "fatal: cannot rename the current branch while not on any." >expect && + test_must_fail git branch -M must-fail 2>err && + test_cmp expect err && + echo "fatal: cannot copy the current branch while not on any." >expect && + test_must_fail git branch -C must-fail 2>err && + test_cmp expect err +' + test_expect_success 'git branch -v -d t should work' ' git branch t && git rev-parse --verify refs/heads/t && |