File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -2529,6 +2529,12 @@ int git_repository_set_head(
25292529 if (error < 0 && error != GIT_ENOTFOUND )
25302530 goto cleanup ;
25312531
2532+ if (ref && current -> type == GIT_REF_SYMBOLIC && git__strcmp (current -> target .symbolic , ref -> name ) &&
2533+ git_reference_is_branch (ref ) && git_branch_is_checked_out (ref )) {
2534+ error = -1 ;
2535+ goto cleanup ;
2536+ }
2537+
25322538 if (!error ) {
25332539 if (git_reference_is_branch (ref )) {
25342540 error = git_reference_symbolic_create (& new_head , repo , GIT_HEAD_FILE ,
Original file line number Diff line number Diff line change @@ -68,6 +68,41 @@ void test_worktree_refs__read_head(void)
6868 git_reference_free (head );
6969}
7070
71+ void test_worktree_refs__set_head_fails_when_worktree_wants_linked_repos_HEAD (void )
72+ {
73+ git_reference * head ;
74+
75+ cl_git_pass (git_repository_head (& head , fixture .repo ));
76+ cl_git_fail (git_repository_set_head (fixture .worktree , git_reference_name (head )));
77+
78+ git_reference_free (head );
79+ }
80+
81+ void test_worktree_refs__set_head_fails_when_main_repo_wants_worktree_head (void )
82+ {
83+ git_reference * head ;
84+
85+ cl_git_pass (git_repository_head (& head , fixture .worktree ));
86+ cl_git_fail (git_repository_set_head (fixture .repo , git_reference_name (head )));
87+
88+ git_reference_free (head );
89+ }
90+
91+ void test_worktree_refs__set_head_works_for_current_HEAD (void )
92+ {
93+ git_reference * head ;
94+
95+ cl_git_pass (git_repository_head (& head , fixture .repo ));
96+ cl_git_pass (git_repository_set_head (fixture .repo , git_reference_name (head )));
97+
98+ git_reference_free (head );
99+ }
100+
101+ void test_worktree_refs__set_head_fails_when_already_checked_out (void )
102+ {
103+ cl_git_fail (git_repository_set_head (fixture .repo , "refs/heads/testrepo-worktree" ));
104+ }
105+
71106void test_worktree_refs__delete_fails_for_checked_out_branch (void )
72107{
73108 git_reference * branch ;
You can’t perform that action at this time.
0 commit comments