mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 12:29:08 +00:00
branch: allow deletion of branch when HEAD's missing
This commit is contained in:
parent
8dd0bef921
commit
0532e7bb87
@ -265,13 +265,19 @@ int git_branch_is_head(
|
||||
{
|
||||
git_reference *head;
|
||||
bool is_same = false;
|
||||
int error;
|
||||
|
||||
assert(branch);
|
||||
|
||||
if (!git_reference_is_branch(branch))
|
||||
return false;
|
||||
|
||||
if (git_repository_head(&head, git_reference_owner(branch)) < 0)
|
||||
error = git_repository_head(&head, git_reference_owner(branch));
|
||||
|
||||
if (error == GIT_ENOTFOUND)
|
||||
return false;
|
||||
|
||||
if (error < 0)
|
||||
return -1;
|
||||
|
||||
is_same = strcmp(
|
||||
|
@ -38,17 +38,16 @@ void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void)
|
||||
git_reference_free(branch);
|
||||
}
|
||||
|
||||
void test_refs_branches_delete__can_not_delete_a_branch_if_HEAD_is_missing(void)
|
||||
void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void)
|
||||
{
|
||||
git_reference *head;
|
||||
git_reference *branch = NULL;
|
||||
git_reference *branch;
|
||||
|
||||
cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
|
||||
git_reference_delete(head);
|
||||
|
||||
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
|
||||
cl_git_fail(git_branch_delete(branch));
|
||||
git_reference_free(branch);
|
||||
cl_git_pass(git_branch_delete(branch));
|
||||
}
|
||||
|
||||
void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)
|
||||
|
Loading…
Reference in New Issue
Block a user