Commit 45f584090818c59ba27ca95b1e930a41c424d6f1

Edward Thomson 2018-01-20T15:15:40

Merge pull request #4484 from pks-t/pks/fail-creating-branch-HEAD branch: refuse creating branches named 'HEAD'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/branch.c b/src/branch.c
index 0697a77..42addc2 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -70,6 +70,12 @@ static int create_branch(
 	assert(branch_name && commit && ref_out);
 	assert(git_object_owner((const git_object *)commit) == repository);
 
+	if (!git__strcmp(branch_name, "HEAD")) {
+		giterr_set(GITERR_REFERENCE, "'HEAD' is not a valid branch name");
+		error = -1;
+		goto cleanup;
+	}
+
 	if (force && !bare && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
 		error = git_branch_is_head(branch);
 		git_reference_free(branch);