From 341a7136f6c38da008544137d2dcc39cfc846279 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 13 May 2012 10:17:52 +0200 Subject: [PATCH] branch: make git_branch_delete() return GIT_ENOTFOUND when the branch doesn't exist --- src/branch.c | 2 +- tests-clar/refs/branches/delete.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/branch.c b/src/branch.c index c980cf08c..6d5880cb2 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 095893020..8ccfaf32f 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); +}