Skip to content

Commit a9677e0

Browse files
committed
branch: refuse creating branches named 'HEAD'
Since a625b092c (branch: correctly reject refs/heads/{-dash,HEAD}, 2017-11-14), which is included in v2.16.0, upstream git refuses to create branches which are named HEAD to avoid ambiguity with the symbolic HEAD reference. Adjust our own code to match that behaviour and reject creating branches names HEAD.
1 parent 4893a9c commit a9677e0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/branch.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static int create_branch(
7070
assert(branch_name && commit && ref_out);
7171
assert(git_object_owner((const git_object *)commit) == repository);
7272

73+
if (!git__strcmp(branch_name, "HEAD")) {
74+
giterr_set(GITERR_REFERENCE, "'HEAD' is not a valid branch name");
75+
error = -1;
76+
goto cleanup;
77+
}
78+
7379
if (force && !bare && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
7480
error = git_branch_is_head(branch);
7581
git_reference_free(branch);

0 commit comments

Comments
 (0)