@@ -218,12 +218,12 @@ void test_worktree_worktree__init(void)
218
218
219
219
void test_worktree_worktree__add_remove_add (void )
220
220
{
221
- git_worktree * wt ;
222
- git_repository * repo ;
223
- git_reference * branch ;
224
- git_buf path = GIT_BUF_INIT ;
225
-
221
+ git_worktree_add_options add_opts = GIT_WORKTREE_ADD_OPTIONS_INIT ;
226
222
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT ;
223
+ git_buf path = GIT_BUF_INIT ;
224
+ git_reference * branch ;
225
+ git_repository * repo ;
226
+ git_worktree * wt ;
227
227
228
228
/* Add the worktree */
229
229
cl_git_pass (git_buf_joinpath (& path , fixture .repo -> workdir , "../worktree-add-remove-add" ));
@@ -233,6 +233,7 @@ void test_worktree_worktree__add_remove_add(void)
233
233
cl_git_pass (git_repository_open (& repo , path .ptr ));
234
234
cl_assert (git__suffixcmp (git_repository_workdir (repo ), "worktree-add-remove-add/" ) == 0 );
235
235
cl_git_pass (git_branch_lookup (& branch , repo , "worktree-add-remove-add" , GIT_BRANCH_LOCAL ));
236
+ git_reference_free (branch );
236
237
git_repository_free (repo );
237
238
238
239
/* Prune the worktree */
@@ -242,18 +243,21 @@ void test_worktree_worktree__add_remove_add(void)
242
243
cl_assert (!git_path_exists (wt -> gitlink_path ));
243
244
git_worktree_free (wt );
244
245
245
- /* Add the worktree back */
246
- cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-add-remove-add" , path .ptr , NULL ));
246
+ /* Add the worktree back with default options should fail. */
247
+ cl_git_fail (git_worktree_add (& wt , fixture .repo , "worktree-add-remove-add" , path .ptr , & add_opts ));
248
+ /* If allowing checkout of existing branches, it should succeed. */
249
+ add_opts .checkout_existing = 1 ;
250
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-add-remove-add" , path .ptr , & add_opts ));
247
251
248
252
/* Open and verify created repo */
249
253
cl_git_pass (git_repository_open (& repo , path .ptr ));
250
254
cl_assert (git__suffixcmp (git_repository_workdir (repo ), "worktree-add-remove-add/" ) == 0 );
251
255
cl_git_pass (git_branch_lookup (& branch , repo , "worktree-add-remove-add" , GIT_BRANCH_LOCAL ));
256
+ git_reference_free (branch );
257
+ git_repository_free (repo );
252
258
253
259
git_buf_dispose (& path );
254
260
git_worktree_free (wt );
255
- git_reference_free (branch );
256
- git_repository_free (repo );
257
261
}
258
262
259
263
void test_worktree_worktree__add_locked (void )
@@ -283,6 +287,7 @@ void test_worktree_worktree__add_locked(void)
283
287
284
288
void test_worktree_worktree__init_existing_branch (void )
285
289
{
290
+ git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT ;
286
291
git_reference * head , * branch ;
287
292
git_commit * commit ;
288
293
git_worktree * wt ;
@@ -293,7 +298,12 @@ void test_worktree_worktree__init_existing_branch(void)
293
298
cl_git_pass (git_branch_create (& branch , fixture .repo , "worktree-new-exist" , commit , false));
294
299
295
300
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 ));
301
+
302
+ /* Add the worktree back with default options should fail. */
303
+ cl_git_fail (git_worktree_add (& wt , fixture .repo , "worktree-new-exist" , path .ptr , NULL ));
304
+ /* If allowing checkout of existing branches, it should succeed. */
305
+ opts .checkout_existing = 1 ;
306
+ cl_git_pass (git_worktree_add (& wt , fixture .repo , "worktree-new-exist" , path .ptr , & opts ));
297
307
298
308
git_buf_dispose (& path );
299
309
git_worktree_free (wt );
@@ -421,7 +431,7 @@ void test_worktree_worktree__name(void)
421
431
422
432
cl_git_pass (git_worktree_lookup (& wt , fixture .repo , "testrepo-worktree" ));
423
433
cl_assert_equal_s (git_worktree_name (wt ), "testrepo-worktree" );
424
-
434
+
425
435
git_worktree_free (wt );
426
436
}
427
437
0 commit comments