@@ -131,3 +131,75 @@ void test_worktree_worktree__lookup_nonexistent_worktree(void)
131131 cl_git_fail (git_worktree_lookup (& wt , fixture .repo , "nonexistent" ));
132132 cl_assert_equal_p (wt , NULL );
133133}
134+
135+ void test_worktree_worktree__open (void )
136+ {
137+ git_worktree * wt ;
138+ git_repository * repo ;
139+
140+ cl_git_pass (git_worktree_lookup (& wt , fixture .repo , "testrepo-worktree" ));
141+
142+ cl_git_pass (git_repository_open_from_worktree (& repo , wt ));
143+ cl_assert_equal_s (git_repository_workdir (repo ),
144+ git_repository_workdir (fixture .worktree ));
145+
146+ git_repository_free (repo );
147+ git_worktree_free (wt );
148+ }
149+
150+ void test_worktree_worktree__open_invalid_commondir (void )
151+ {
152+ git_worktree * wt ;
153+ git_repository * repo ;
154+ git_buf buf = GIT_BUF_INIT , path = GIT_BUF_INIT ;
155+
156+ cl_git_pass (git_buf_sets (& buf , "/path/to/nonexistent/commondir" ));
157+ cl_git_pass (git_buf_printf (& path ,
158+ "%s/worktrees/testrepo-worktree/commondir" ,
159+ fixture .repo -> commondir ));
160+ cl_git_pass (git_futils_writebuffer (& buf , path .ptr , O_RDWR , 0644 ));
161+
162+ cl_git_pass (git_worktree_lookup (& wt , fixture .repo , "testrepo-worktree" ));
163+ cl_git_fail (git_repository_open_from_worktree (& repo , wt ));
164+
165+ git_buf_free (& buf );
166+ git_buf_free (& path );
167+ git_worktree_free (wt );
168+ }
169+
170+ void test_worktree_worktree__open_invalid_gitdir (void )
171+ {
172+ git_worktree * wt ;
173+ git_repository * repo ;
174+ git_buf buf = GIT_BUF_INIT , path = GIT_BUF_INIT ;
175+
176+ cl_git_pass (git_buf_sets (& buf , "/path/to/nonexistent/gitdir" ));
177+ cl_git_pass (git_buf_printf (& path ,
178+ "%s/worktrees/testrepo-worktree/gitdir" ,
179+ fixture .repo -> commondir ));
180+ cl_git_pass (git_futils_writebuffer (& buf , path .ptr , O_RDWR , 0644 ));
181+
182+ cl_git_pass (git_worktree_lookup (& wt , fixture .repo , "testrepo-worktree" ));
183+ cl_git_fail (git_repository_open_from_worktree (& repo , wt ));
184+
185+ git_buf_free (& buf );
186+ git_buf_free (& path );
187+ git_worktree_free (wt );
188+ }
189+
190+ void test_worktree_worktree__open_invalid_parent (void )
191+ {
192+ git_worktree * wt ;
193+ git_repository * repo ;
194+ git_buf buf = GIT_BUF_INIT ;
195+
196+ cl_git_pass (git_buf_sets (& buf , "/path/to/nonexistent/gitdir" ));
197+ cl_git_pass (git_futils_writebuffer (& buf ,
198+ fixture .worktree -> path_gitlink , O_RDWR , 0644 ));
199+
200+ cl_git_pass (git_worktree_lookup (& wt , fixture .repo , "testrepo-worktree" ));
201+ cl_git_fail (git_repository_open_from_worktree (& repo , wt ));
202+
203+ git_buf_free (& buf );
204+ git_worktree_free (wt );
205+ }
0 commit comments