Commit 0532e7bb87713921f34f24ba5599d3b4d2922e1e

nulltoken 2012-10-19T20:34:33

branch: allow deletion of branch when HEAD's missing

diff --git a/src/branch.c b/src/branch.c
index d0bd1c4..d9fa9eb 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -265,13 +265,19 @@ int git_branch_is_head(
 {
 	git_reference *head;
 	bool is_same = false;
+	int error;
 
 	assert(branch);
 
 	if (!git_reference_is_branch(branch))
 		return false;
 
-	if (git_repository_head(&head, git_reference_owner(branch)) < 0)
+	error = git_repository_head(&head, git_reference_owner(branch));
+
+	if (error == GIT_ENOTFOUND)
+		return false;
+
+	if (error < 0)
 		return -1;
 
 	is_same = strcmp(
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index b261240..1a97dc8 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -38,17 +38,16 @@ void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void)
 	git_reference_free(branch);
 }
 
-void test_refs_branches_delete__can_not_delete_a_branch_if_HEAD_is_missing(void)
+void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void)
 {
 	git_reference *head;
-	git_reference *branch = NULL;
+	git_reference *branch;
 
 	cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
 	git_reference_delete(head);
 
 	cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
-	cl_git_fail(git_branch_delete(branch));
-	git_reference_free(branch);
+	cl_git_pass(git_branch_delete(branch));
 }
 
 void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)