Merge branch 'jc/branch-name-sanity'
"git branch" and "git checkout -b" are now forbidden from creating a branch whose name is "HEAD". * jc/branch-name-sanity: builtin/branch: remove redundant check for HEAD branch: correctly reject refs/heads/{-dash,HEAD} branch: split validate_new_branchname() into two branch: streamline "attr_only" handling in validate_new_branchname()
This commit is contained in:
@ -331,4 +331,47 @@ test_expect_success 'update-ref --stdin -z fails delete with bad ref name' '
|
||||
grep "fatal: invalid ref format: ~a" err
|
||||
'
|
||||
|
||||
test_expect_success 'branch rejects HEAD as a branch name' '
|
||||
test_must_fail git branch HEAD HEAD^ &&
|
||||
test_must_fail git show-ref refs/heads/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'checkout -b rejects HEAD as a branch name' '
|
||||
test_must_fail git checkout -B HEAD HEAD^ &&
|
||||
test_must_fail git show-ref refs/heads/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'update-ref can operate on refs/heads/HEAD' '
|
||||
git update-ref refs/heads/HEAD HEAD^ &&
|
||||
git show-ref refs/heads/HEAD &&
|
||||
git update-ref -d refs/heads/HEAD &&
|
||||
test_must_fail git show-ref refs/heads/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'branch -d can remove refs/heads/HEAD' '
|
||||
git update-ref refs/heads/HEAD HEAD^ &&
|
||||
git branch -d HEAD &&
|
||||
test_must_fail git show-ref refs/heads/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'branch -m can rename refs/heads/HEAD' '
|
||||
git update-ref refs/heads/HEAD HEAD^ &&
|
||||
git branch -m HEAD tail &&
|
||||
test_must_fail git show-ref refs/heads/HEAD &&
|
||||
git show-ref refs/heads/tail
|
||||
'
|
||||
|
||||
test_expect_success 'branch -d can remove refs/heads/-dash' '
|
||||
git update-ref refs/heads/-dash HEAD^ &&
|
||||
git branch -d -- -dash &&
|
||||
test_must_fail git show-ref refs/heads/-dash
|
||||
'
|
||||
|
||||
test_expect_success 'branch -m can rename refs/heads/-dash' '
|
||||
git update-ref refs/heads/-dash HEAD^ &&
|
||||
git branch -m -- -dash dash &&
|
||||
test_must_fail git show-ref refs/heads/-dash &&
|
||||
git show-ref refs/heads/dash
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user