mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 03:15:46 +00:00
Merge pull request #692 from nulltoken/fix/delete-branch_ENOTFOUND
branch: make git_branch_delete() return GIT_ENOTFOUND when the branch doesn't exist
This commit is contained in:
commit
8c6329eec9
@ -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.");
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user