Commit 8c6329ee by Vicent Martí

Merge pull request #692 from nulltoken/fix/delete-branch_ENOTFOUND

branch: make git_branch_delete() return GIT_ENOTFOUND when the branch doesn't exist
parents c9e9ec97 341a7136
...@@ -114,7 +114,7 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_ ...@@ -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)); 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) 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) { if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) {
giterr_set(GITERR_REFERENCE, "Cannot locate HEAD."); giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
......
...@@ -74,3 +74,18 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void) ...@@ -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)); 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment