Commit 62993b61586be9d838e52fef3b7e01ec3abd8c35

nulltoken 2012-10-11T14:08:32

branches: propagate EEXISTS upon creation

diff --git a/src/branch.c b/src/branch.c
index 6d497b0..d0bd1c4 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -77,12 +77,11 @@ int git_branch_create(
 	if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
 		goto cleanup;
 
-	if (git_reference_create_oid(&branch, repository,
-		git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
-		goto cleanup;
+	error = git_reference_create_oid(&branch, repository,
+		git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);
 
-	*ref_out = branch;
-	error = 0;
+	if (!error)
+		*ref_out = branch;
 
 cleanup:
 	git_object_free(commit);
diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c
index fe72d47..9026b0d 100644
--- a/tests-clar/refs/branches/create.c
+++ b/tests-clar/refs/branches/create.c
@@ -50,7 +50,7 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with
 {
 	retrieve_known_commit(&target, repo);
 
-	cl_git_fail(git_branch_create(&branch, repo, "br2", target, 0));
+	cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0));
 }
 
 void test_refs_branches_create__can_force_create_over_an_existing_branch(void)