mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-22 22:20:02 +00:00
repository: restrict checking out checked out branches
If a branch is already checked out in a working tree we are not allowed to check out that branch in another repository. Introduce this restriction when setting a repository's HEAD.
This commit is contained in:
parent
143e539fd0
commit
384518d09d
@ -2529,6 +2529,12 @@ int git_repository_set_head(
|
|||||||
if (error < 0 && error != GIT_ENOTFOUND)
|
if (error < 0 && error != GIT_ENOTFOUND)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (ref && current->type == GIT_REF_SYMBOLIC && git__strcmp(current->target.symbolic, ref->name) &&
|
||||||
|
git_reference_is_branch(ref) && git_branch_is_checked_out(ref)) {
|
||||||
|
error = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
if (git_reference_is_branch(ref)) {
|
if (git_reference_is_branch(ref)) {
|
||||||
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
||||||
|
@ -68,6 +68,41 @@ void test_worktree_refs__read_head(void)
|
|||||||
git_reference_free(head);
|
git_reference_free(head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_worktree_refs__set_head_fails_when_worktree_wants_linked_repos_HEAD(void)
|
||||||
|
{
|
||||||
|
git_reference *head;
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_head(&head, fixture.repo));
|
||||||
|
cl_git_fail(git_repository_set_head(fixture.worktree, git_reference_name(head)));
|
||||||
|
|
||||||
|
git_reference_free(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_worktree_refs__set_head_fails_when_main_repo_wants_worktree_head(void)
|
||||||
|
{
|
||||||
|
git_reference *head;
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_head(&head, fixture.worktree));
|
||||||
|
cl_git_fail(git_repository_set_head(fixture.repo, git_reference_name(head)));
|
||||||
|
|
||||||
|
git_reference_free(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_worktree_refs__set_head_works_for_current_HEAD(void)
|
||||||
|
{
|
||||||
|
git_reference *head;
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_head(&head, fixture.repo));
|
||||||
|
cl_git_pass(git_repository_set_head(fixture.repo, git_reference_name(head)));
|
||||||
|
|
||||||
|
git_reference_free(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_worktree_refs__set_head_fails_when_already_checked_out(void)
|
||||||
|
{
|
||||||
|
cl_git_fail(git_repository_set_head(fixture.repo, "refs/heads/testrepo-worktree"));
|
||||||
|
}
|
||||||
|
|
||||||
void test_worktree_refs__delete_fails_for_checked_out_branch(void)
|
void test_worktree_refs__delete_fails_for_checked_out_branch(void)
|
||||||
{
|
{
|
||||||
git_reference *branch;
|
git_reference *branch;
|
||||||
|
Loading…
Reference in New Issue
Block a user