Branch names with reference prefixes results in buggy branches
Summary
Creating branches with names starting with "refs/heads/" or "refs/remotes/" results in "half created" branches.
Steps to reproduce
- Create a project
- Create a branch (branch name "refs/heads/:branch_name" or "refs/remotes/:branch_name")
Expected behavior
The branch should be either created with its prefix stripped or not created.
Actual behavior
- We get an "Invalid reference name" but the branch was created
- Checking the branch page leads to a 404
- Trying to remove the branch leads to a 404
The only way to remove the branch is to remove the whole repository.
Possible fixes
This error is caused by rugged which is passing the reference name as-is on creation (https://github.com/libgit2/rugged/blob/master/ext/rugged/rugged_branch_collection.c#L133) but routing the reference lookup based on the prefix (https://github.com/libgit2/rugged/blob/master/ext/rugged/rugged_branch_collection.c#L35-L37).
Stripping special prefixes at the beginning of CreateBranchService.execute is probably (https://gitlab.com/gitlab-org/gitlab-ce/blob/8ab94120ee0a87c7b1158ebafea101e3952ec758/app/services/create_branch_service.rb ) the way to go.