Commit 341a7136f6c38da008544137d2dcc39cfc846279

nulltoken 2012-05-13T10:17:52

branch: make git_branch_delete() return GIT_ENOTFOUND when the branch doesn't exist

diff --git a/src/branch.c b/src/branch.c
index c980cf0..6d5880c 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -114,7 +114,7 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
 	assert((branch_type == GIT_BRANCH_LOCAL) || (branch_type == GIT_BRANCH_REMOTE));
 
 	if ((error = retrieve_branch_reference(&branch, repo, branch_name, branch_type == GIT_BRANCH_REMOTE)) < 0)
-		goto on_error;
+		return error;
 
 	if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) {
 		giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 0958930..8ccfaf3 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -74,3 +74,18 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void)
 {
 	cl_git_pass(git_branch_delete(repo, "nulltoken/master", GIT_BRANCH_REMOTE));
 }
+
+static void assert_non_exisitng_branch_removal(const char *branch_name, git_branch_type branch_type)
+{
+	int error; 
+	error = git_branch_delete(repo, branch_name, branch_type);
+
+	cl_git_fail(error);
+	cl_assert_equal_i(GIT_ENOTFOUND, error);
+}
+
+void test_refs_branches_delete__deleting_a_non_existing_branch_returns_ENOTFOUND(void)
+{
+	assert_non_exisitng_branch_removal("i-do-not-locally-exist", GIT_BRANCH_LOCAL);
+	assert_non_exisitng_branch_removal("neither/remotely", GIT_BRANCH_REMOTE);
+}