mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
branch: deploy git_branch_is_head()
This commit is contained in:
parent
0c78f685eb
commit
4ba23be1e5
29
src/branch.c
29
src/branch.c
@ -92,7 +92,7 @@ cleanup:
|
|||||||
|
|
||||||
int git_branch_delete(git_reference *branch)
|
int git_branch_delete(git_reference *branch)
|
||||||
{
|
{
|
||||||
git_reference *head = NULL;
|
int is_head;
|
||||||
|
|
||||||
assert(branch);
|
assert(branch);
|
||||||
|
|
||||||
@ -102,27 +102,16 @@ int git_branch_delete(git_reference *branch)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (git_reference_lookup(&head, git_reference_owner(branch), GIT_HEAD_FILE) < 0) {
|
if ((is_head = git_branch_is_head(branch)) < 0)
|
||||||
giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
|
return is_head;
|
||||||
goto on_error;
|
|
||||||
|
if (is_head) {
|
||||||
|
giterr_set(GITERR_REFERENCE,
|
||||||
|
"Cannot delete branch '%s' as it is the current HEAD of the repository.", git_reference_name(branch));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((git_reference_type(head) == GIT_REF_SYMBOLIC)
|
return git_reference_delete(branch);
|
||||||
&& (strcmp(git_reference_target(head), git_reference_name(branch)) == 0)) {
|
|
||||||
giterr_set(GITERR_REFERENCE,
|
|
||||||
"Cannot delete branch '%s' as it is the current HEAD of the repository.", git_reference_name(branch));
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (git_reference_delete(branch) < 0)
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
git_reference_free(head);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
on_error:
|
|
||||||
git_reference_free(head);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <git2/tag.h>
|
#include <git2/tag.h>
|
||||||
#include <git2/object.h>
|
#include <git2/object.h>
|
||||||
#include <git2/oid.h>
|
#include <git2/oid.h>
|
||||||
|
#include <git2/branch.h>
|
||||||
|
|
||||||
GIT__USE_STRMAP;
|
GIT__USE_STRMAP;
|
||||||
|
|
||||||
@ -1345,9 +1346,6 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
|
|||||||
char normalized[GIT_REFNAME_MAX];
|
char normalized[GIT_REFNAME_MAX];
|
||||||
bool should_head_be_updated = false;
|
bool should_head_be_updated = false;
|
||||||
|
|
||||||
const char *head_target = NULL;
|
|
||||||
git_reference *head = NULL;
|
|
||||||
|
|
||||||
normalization_flags = ref->flags & GIT_REF_SYMBOLIC ?
|
normalization_flags = ref->flags & GIT_REF_SYMBOLIC ?
|
||||||
GIT_REF_FORMAT_ALLOW_ONELEVEL
|
GIT_REF_FORMAT_ALLOW_ONELEVEL
|
||||||
: GIT_REF_FORMAT_NORMAL;
|
: GIT_REF_FORMAT_NORMAL;
|
||||||
@ -1370,12 +1368,9 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
|
|||||||
/*
|
/*
|
||||||
* Check if we have to update HEAD.
|
* Check if we have to update HEAD.
|
||||||
*/
|
*/
|
||||||
if (git_repository_head(&head, ref->owner) < 0)
|
if ((should_head_be_updated = git_branch_is_head(ref)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
should_head_be_updated = !strcmp(git_reference_name(head), ref->name);
|
|
||||||
git_reference_free(head);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now delete the old ref and remove an possibly existing directory
|
* Now delete the old ref and remove an possibly existing directory
|
||||||
* named `new_name`. Note that using the internal `reference_delete`
|
* named `new_name`. Note that using the internal `reference_delete`
|
||||||
|
Loading…
Reference in New Issue
Block a user