@@ -216,6 +216,48 @@ 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
+
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
+
254
+ git_buf_dispose (& path );
255
+ git_worktree_free (wt );
256
+ git_reference_free (branch );
257
+ git_repository_free (repo );
258
+ }
259
+
260
+
219
261
void test_worktree_worktree__add_locked (void )
220
262
{
221
263
git_worktree * wt ;
@@ -250,12 +292,13 @@ void test_worktree_worktree__init_existing_branch(void)
250
292
251
293
cl_git_pass (git_repository_head (& head , fixture .repo ));
252
294
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));
295
+ cl_git_pass (git_branch_create (& branch , fixture .repo , "worktree-new-exist " , commit , false));
254
296
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 ));
297
+ cl_git_pass (git_buf_joinpath (& path , fixture .repo -> workdir , "../worktree-new-exist " ));
298
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-new-exist " , path .ptr , NULL ));
257
299
258
300
git_buf_dispose (& path );
301
+ git_worktree_free (wt );
259
302
git_commit_free (commit );
260
303
git_reference_free (head );
261
304
git_reference_free (branch );
0 commit comments