@@ -216,6 +216,46 @@ void test_worktree_worktree__init(void)
216
216
git_repository_free (repo );
217
217
}
218
218
219
+ void test_worktree_worktree__add_remove_add (void )
220
+ {
221
+ git_worktree * wt ;
222
+ git_repository * repo ;
223
+ git_reference * branch ;
224
+ git_buf path = GIT_BUF_INIT ;
225
+
226
+ git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT ;
227
+
228
+ /* Add the worktree */
229
+ cl_git_pass (git_buf_joinpath (& path , fixture .repo -> workdir , "../worktree-add-remove-add" ));
230
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-add-remove-add" , path .ptr , NULL ));
231
+
232
+ /* Open and verify created repo */
233
+ cl_git_pass (git_repository_open (& repo , path .ptr ));
234
+ cl_assert (git__suffixcmp (git_repository_workdir (repo ), "worktree-add-remove-add/" ) == 0 );
235
+ cl_git_pass (git_branch_lookup (& branch , repo , "worktree-add-remove-add" , GIT_BRANCH_LOCAL ));
236
+ git_repository_free (repo );
237
+
238
+ /* Prune the worktree */
239
+ opts .flags = GIT_WORKTREE_PRUNE_VALID |GIT_WORKTREE_PRUNE_WORKING_TREE ;
240
+ cl_git_pass (git_worktree_prune (wt , & opts ));
241
+ cl_assert (!git_path_exists (wt -> gitdir_path ));
242
+ cl_assert (!git_path_exists (wt -> gitlink_path ));
243
+ git_worktree_free (wt );
244
+
245
+ /* Add the worktree back */
246
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-add-remove-add" , path .ptr , NULL ));
247
+
248
+ /* Open and verify created repo */
249
+ cl_git_pass (git_repository_open (& repo , path .ptr ));
250
+ cl_assert (git__suffixcmp (git_repository_workdir (repo ), "worktree-add-remove-add/" ) == 0 );
251
+ cl_git_pass (git_branch_lookup (& branch , repo , "worktree-add-remove-add" , GIT_BRANCH_LOCAL ));
252
+
253
+ git_buf_dispose (& path );
254
+ git_worktree_free (wt );
255
+ git_reference_free (branch );
256
+ git_repository_free (repo );
257
+ }
258
+
219
259
void test_worktree_worktree__add_locked (void )
220
260
{
221
261
git_worktree * wt ;
@@ -250,12 +290,13 @@ void test_worktree_worktree__init_existing_branch(void)
250
290
251
291
cl_git_pass (git_repository_head (& head , fixture .repo ));
252
292
cl_git_pass (git_commit_lookup (& commit , fixture .repo , & head -> target .oid ));
253
- cl_git_pass (git_branch_create (& branch , fixture .repo , "worktree-new" , commit , false));
293
+ cl_git_pass (git_branch_create (& branch , fixture .repo , "worktree-new-exist " , commit , false));
254
294
255
- cl_git_pass (git_buf_joinpath (& path , fixture .repo -> workdir , "../worktree-new" ));
256
- cl_git_fail (git_worktree_add (& wt , fixture .repo , "worktree-new" , path .ptr , NULL ));
295
+ cl_git_pass (git_buf_joinpath (& path , fixture .repo -> workdir , "../worktree-new-exist " ));
296
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-new-exist " , path .ptr , NULL ));
257
297
258
298
git_buf_dispose (& path );
299
+ git_worktree_free (wt );
259
300
git_commit_free (commit );
260
301
git_reference_free (head );
261
302
git_reference_free (branch );
0 commit comments