summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-14 11:25:40 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-14 11:25:40 -0700
commit8c6329eec963a7702d3db47ef00ad02d0ec4e4c3 (patch)
tree058e07759abf53b3ae65a433946f59235f526c48
parentc9e9ec97d298ade86c3cbd089ed217b54d6319d4 (diff)
parent341a7136f6c38da008544137d2dcc39cfc846279 (diff)
downloadlibgit2-8c6329eec963a7702d3db47ef00ad02d0ec4e4c3.tar.gz
Merge pull request #692 from nulltoken/fix/delete-branch_ENOTFOUND
branch: make git_branch_delete() return GIT_ENOTFOUND when the branch doesn't exist
-rw-r--r--src/branch.c2
-rw-r--r--tests-clar/refs/branches/delete.c15
2 files changed, 16 insertions, 1 deletions
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);
+}