]> git.proxmox.com Git - libgit2.git/blob - tests/libgit2/worktree/worktree.c
New upstream version 1.5.0+ds
[libgit2.git] / tests / libgit2 / worktree / worktree.c
1 #include "clar_libgit2.h"
2 #include "worktree_helpers.h"
3 #include "submodule/submodule_helpers.h"
4
5 #include "checkout.h"
6 #include "repository.h"
7 #include "worktree.h"
8
9 #define COMMON_REPO "testrepo"
10 #define WORKTREE_REPO "testrepo-worktree"
11
12 static worktree_fixture fixture =
13 WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
14
15 void test_worktree_worktree__initialize(void)
16 {
17 setup_fixture_worktree(&fixture);
18 }
19
20 void test_worktree_worktree__cleanup(void)
21 {
22 cleanup_fixture_worktree(&fixture);
23 }
24
25 void test_worktree_worktree__list(void)
26 {
27 git_strarray wts;
28
29 cl_git_pass(git_worktree_list(&wts, fixture.repo));
30 cl_assert_equal_i(wts.count, 1);
31 cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
32
33 git_strarray_dispose(&wts);
34 }
35
36 void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
37 {
38 const char *filesets[3][2] = {
39 { "gitdir", "commondir" },
40 { "gitdir", "HEAD" },
41 { "HEAD", "commondir" },
42 };
43 git_str path = GIT_STR_INIT;
44 git_strarray wts;
45 size_t i, j, len;
46
47 cl_git_pass(git_str_joinpath(&path,
48 fixture.repo->commondir,
49 "worktrees/invalid"));
50 cl_git_pass(p_mkdir(path.ptr, 0755));
51
52 len = path.size;
53
54 for (i = 0; i < ARRAY_SIZE(filesets); i++) {
55
56 for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
57 git_str_truncate(&path, len);
58 cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
59 cl_git_pass(p_close(p_creat(path.ptr, 0644)));
60 }
61
62 cl_git_pass(git_worktree_list(&wts, fixture.worktree));
63 cl_assert_equal_i(wts.count, 1);
64 cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
65 git_strarray_dispose(&wts);
66
67 for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
68 git_str_truncate(&path, len);
69 cl_git_pass(git_str_joinpath(&path, path.ptr, filesets[i][j]));
70 p_unlink(path.ptr);
71 }
72 }
73
74 git_str_dispose(&path);
75 }
76
77 void test_worktree_worktree__list_in_worktree_repo(void)
78 {
79 git_strarray wts;
80
81 cl_git_pass(git_worktree_list(&wts, fixture.worktree));
82 cl_assert_equal_i(wts.count, 1);
83 cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
84
85 git_strarray_dispose(&wts);
86 }
87
88 void test_worktree_worktree__list_without_worktrees(void)
89 {
90 git_repository *repo;
91 git_strarray wts;
92
93 repo = cl_git_sandbox_init("testrepo2");
94 cl_git_pass(git_worktree_list(&wts, repo));
95 cl_assert_equal_i(wts.count, 0);
96
97 git_repository_free(repo);
98 }
99
100 void test_worktree_worktree__lookup(void)
101 {
102 git_worktree *wt;
103 git_str gitdir_path = GIT_STR_INIT;
104
105 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
106
107 cl_git_pass(git_str_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
108
109 cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
110 cl_assert_equal_s(wt->parent_path, fixture.repo->workdir);
111 cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
112 cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir);
113 cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
114
115 git_str_dispose(&gitdir_path);
116 git_worktree_free(wt);
117 }
118
119 void test_worktree_worktree__lookup_nonexistent_worktree(void)
120 {
121 git_worktree *wt;
122
123 cl_git_fail(git_worktree_lookup(&wt, fixture.repo, "nonexistent"));
124 cl_assert_equal_p(wt, NULL);
125 }
126
127 void test_worktree_worktree__open(void)
128 {
129 git_worktree *wt;
130 git_repository *repo;
131
132 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
133
134 cl_git_pass(git_repository_open_from_worktree(&repo, wt));
135 cl_assert_equal_s(git_repository_workdir(repo),
136 git_repository_workdir(fixture.worktree));
137
138 git_repository_free(repo);
139 git_worktree_free(wt);
140 }
141
142 void test_worktree_worktree__open_invalid_commondir(void)
143 {
144 git_worktree *wt;
145 git_repository *repo;
146 git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
147
148 cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/commondir"));
149 cl_git_pass(git_str_joinpath(&path,
150 fixture.repo->commondir,
151 "worktrees/testrepo-worktree/commondir"));
152 cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
153
154 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
155 cl_git_fail(git_repository_open_from_worktree(&repo, wt));
156
157 git_str_dispose(&buf);
158 git_str_dispose(&path);
159 git_worktree_free(wt);
160 }
161
162 void test_worktree_worktree__open_invalid_gitdir(void)
163 {
164 git_worktree *wt;
165 git_repository *repo;
166 git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
167
168 cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
169 cl_git_pass(git_str_joinpath(&path,
170 fixture.repo->commondir,
171 "worktrees/testrepo-worktree/gitdir"));
172 cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
173
174 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
175 cl_git_fail(git_repository_open_from_worktree(&repo, wt));
176
177 git_str_dispose(&buf);
178 git_str_dispose(&path);
179 git_worktree_free(wt);
180 }
181
182 void test_worktree_worktree__open_invalid_parent(void)
183 {
184 git_worktree *wt;
185 git_repository *repo;
186 git_str buf = GIT_STR_INIT;
187
188 cl_git_pass(git_str_sets(&buf, "/path/to/nonexistent/gitdir"));
189 cl_git_pass(git_futils_writebuffer(&buf,
190 fixture.worktree->gitlink, O_RDWR, 0644));
191
192 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
193 cl_git_fail(git_repository_open_from_worktree(&repo, wt));
194
195 git_str_dispose(&buf);
196 git_worktree_free(wt);
197 }
198
199 void test_worktree_worktree__init(void)
200 {
201 git_worktree *wt;
202 git_repository *repo;
203 git_reference *branch;
204 git_str path = GIT_STR_INIT;
205
206 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
207 cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
208
209 /* Open and verify created repo */
210 cl_git_pass(git_repository_open(&repo, path.ptr));
211 cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-new/") == 0);
212 cl_git_pass(git_branch_lookup(&branch, repo, "worktree-new", GIT_BRANCH_LOCAL));
213
214 git_str_dispose(&path);
215 git_worktree_free(wt);
216 git_reference_free(branch);
217 git_repository_free(repo);
218 }
219
220 void test_worktree_worktree__add_locked(void)
221 {
222 git_worktree *wt;
223 git_repository *repo;
224 git_reference *branch;
225 git_str path = GIT_STR_INIT;
226 git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
227
228 opts.lock = 1;
229
230 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
231 cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
232
233 /* Open and verify created repo */
234 cl_assert(git_worktree_is_locked(NULL, wt));
235 cl_git_pass(git_repository_open(&repo, path.ptr));
236 cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
237 cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
238
239 git_str_dispose(&path);
240 git_worktree_free(wt);
241 git_reference_free(branch);
242 git_repository_free(repo);
243 }
244
245 void test_worktree_worktree__init_existing_branch(void)
246 {
247 git_reference *head, *branch;
248 git_commit *commit;
249 git_worktree *wt;
250 git_str path = GIT_STR_INIT;
251
252 cl_git_pass(git_repository_head(&head, fixture.repo));
253 cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
254 cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
255
256 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
257 cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
258
259 git_str_dispose(&path);
260 git_commit_free(commit);
261 git_reference_free(head);
262 git_reference_free(branch);
263 }
264
265 void test_worktree_worktree__add_with_explicit_branch(void)
266 {
267 git_reference *head, *branch, *wthead;
268 git_commit *commit;
269 git_worktree *wt;
270 git_repository *wtrepo;
271 git_str path = GIT_STR_INIT;
272 git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
273
274 cl_git_pass(git_repository_head(&head, fixture.repo));
275 cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
276 cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-with-ref", commit, false));
277
278 opts.ref = branch;
279
280 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
281 cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-with-different-name", path.ptr, &opts));
282 cl_git_pass(git_repository_open_from_worktree(&wtrepo, wt));
283 cl_git_pass(git_repository_head(&wthead, wtrepo));
284 cl_assert_equal_s(git_reference_name(wthead), "refs/heads/worktree-with-ref");
285
286 git_str_dispose(&path);
287 git_commit_free(commit);
288 git_reference_free(head);
289 git_reference_free(branch);
290 git_reference_free(wthead);
291 git_repository_free(wtrepo);
292 git_worktree_free(wt);
293 }
294
295 void test_worktree_worktree__add_no_checkout(void)
296 {
297 git_worktree *wt;
298 git_repository *wtrepo;
299 git_index *index;
300 git_str path = GIT_STR_INIT;
301 git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
302
303 opts.checkout_options.checkout_strategy = GIT_CHECKOUT_NONE;
304
305 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-no-checkout"));
306 cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-no-checkout", path.ptr, &opts));
307
308 cl_git_pass(git_repository_open(&wtrepo, path.ptr));
309 cl_git_pass(git_repository_index(&index, wtrepo));
310 cl_assert_equal_i(git_index_entrycount(index), 0);
311
312 git_str_dispose(&path);
313 git_worktree_free(wt);
314 git_index_free(index);
315 git_repository_free(wtrepo);
316 }
317
318 void test_worktree_worktree__init_existing_worktree(void)
319 {
320 git_worktree *wt;
321 git_str path = GIT_STR_INIT;
322
323 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
324 cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
325
326 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
327 cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
328
329 git_str_dispose(&path);
330 git_worktree_free(wt);
331 }
332
333 void test_worktree_worktree__init_existing_path(void)
334 {
335 const char *wtfiles[] = { "HEAD", "commondir", "gitdir", "index" };
336 git_worktree *wt;
337 git_str path = GIT_STR_INIT;
338 unsigned i;
339
340 /* Delete files to verify they have not been created by
341 * the init call */
342 for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
343 cl_git_pass(git_str_joinpath(&path,
344 fixture.worktree->gitdir, wtfiles[i]));
345 cl_git_pass(p_unlink(path.ptr));
346 }
347
348 cl_git_pass(git_str_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
349 cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
350
351 /* Verify files have not been re-created */
352 for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
353 cl_git_pass(git_str_joinpath(&path,
354 fixture.worktree->gitdir, wtfiles[i]));
355 cl_assert(!git_fs_path_exists(path.ptr));
356 }
357
358 git_str_dispose(&path);
359 }
360
361 void test_worktree_worktree__init_submodule(void)
362 {
363 git_repository *repo, *sm, *wt;
364 git_worktree *worktree;
365 git_str path = GIT_STR_INIT;
366
367 cleanup_fixture_worktree(&fixture);
368 repo = setup_fixture_submod2();
369
370 cl_git_pass(git_str_joinpath(&path, repo->workdir, "sm_unchanged"));
371 cl_git_pass(git_repository_open(&sm, path.ptr));
372 cl_git_pass(git_str_joinpath(&path, repo->workdir, "../worktree/"));
373 cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
374 cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
375
376 cl_git_pass(git_fs_path_prettify_dir(&path, path.ptr, NULL));
377 cl_assert_equal_s(path.ptr, wt->workdir);
378 cl_git_pass(git_fs_path_prettify_dir(&path, sm->commondir, NULL));
379 cl_assert_equal_s(sm->commondir, wt->commondir);
380
381 cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
382 cl_assert_equal_s(path.ptr, wt->gitdir);
383
384 git_str_dispose(&path);
385 git_worktree_free(worktree);
386 git_repository_free(sm);
387 git_repository_free(wt);
388 }
389
390 void test_worktree_worktree__validate(void)
391 {
392 git_worktree *wt;
393
394 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
395 cl_git_pass(git_worktree_validate(wt));
396
397 git_worktree_free(wt);
398 }
399
400 void test_worktree_worktree__name(void)
401 {
402 git_worktree *wt;
403
404 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
405 cl_assert_equal_s(git_worktree_name(wt), "testrepo-worktree");
406
407 git_worktree_free(wt);
408 }
409
410 void test_worktree_worktree__path(void)
411 {
412 git_worktree *wt;
413 git_str expected_path = GIT_STR_INIT;
414
415 cl_git_pass(git_str_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
416 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
417 cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr);
418
419 git_str_dispose(&expected_path);
420 git_worktree_free(wt);
421 }
422
423 void test_worktree_worktree__validate_invalid_commondir(void)
424 {
425 git_worktree *wt;
426
427 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
428 git__free(wt->commondir_path);
429 wt->commondir_path = "/path/to/invalid/commondir";
430
431 cl_git_fail(git_worktree_validate(wt));
432
433 wt->commondir_path = NULL;
434 git_worktree_free(wt);
435 }
436
437 void test_worktree_worktree__validate_invalid_gitdir(void)
438 {
439 git_worktree *wt;
440
441 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
442 git__free(wt->gitdir_path);
443 wt->gitdir_path = "/path/to/invalid/gitdir";
444 cl_git_fail(git_worktree_validate(wt));
445
446 wt->gitdir_path = NULL;
447 git_worktree_free(wt);
448 }
449
450 void test_worktree_worktree__validate_invalid_parent(void)
451 {
452 git_worktree *wt;
453
454 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
455 git__free(wt->parent_path);
456 wt->parent_path = "/path/to/invalid/parent";
457 cl_git_fail(git_worktree_validate(wt));
458
459 wt->parent_path = NULL;
460 git_worktree_free(wt);
461 }
462
463 void test_worktree_worktree__lock_with_reason(void)
464 {
465 git_worktree *wt;
466 git_buf reason = GIT_BUF_INIT;
467
468 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
469
470 cl_assert(!git_worktree_is_locked(NULL, wt));
471 cl_git_pass(git_worktree_lock(wt, "because"));
472 cl_assert(git_worktree_is_locked(&reason, wt) > 0);
473 cl_assert_equal_s(reason.ptr, "because");
474 cl_assert(wt->locked);
475
476 git_buf_dispose(&reason);
477 git_worktree_free(wt);
478 }
479
480 void test_worktree_worktree__lock_without_reason(void)
481 {
482 git_worktree *wt;
483 git_buf reason = GIT_BUF_INIT;
484
485 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
486
487 cl_assert(!git_worktree_is_locked(NULL, wt));
488 cl_git_pass(git_worktree_lock(wt, NULL));
489 cl_assert(git_worktree_is_locked(&reason, wt) > 0);
490 cl_assert_equal_i(reason.size, 0);
491 cl_assert(wt->locked);
492
493 git_buf_dispose(&reason);
494 git_worktree_free(wt);
495 }
496
497 void test_worktree_worktree__unlock_unlocked_worktree(void)
498 {
499 git_worktree *wt;
500
501 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
502 cl_assert(!git_worktree_is_locked(NULL, wt));
503 cl_assert_equal_i(1, git_worktree_unlock(wt));
504 cl_assert(!wt->locked);
505
506 git_worktree_free(wt);
507 }
508
509 void test_worktree_worktree__unlock_locked_worktree(void)
510 {
511 git_worktree *wt;
512
513 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
514 cl_git_pass(git_worktree_lock(wt, NULL));
515 cl_assert(git_worktree_is_locked(NULL, wt));
516 cl_assert_equal_i(0, git_worktree_unlock(wt));
517 cl_assert(!wt->locked);
518
519 git_worktree_free(wt);
520 }
521
522 void test_worktree_worktree__prune_without_opts_fails(void)
523 {
524 git_worktree *wt;
525 git_repository *repo;
526
527 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
528 cl_git_fail(git_worktree_prune(wt, NULL));
529
530 /* Assert the repository is still valid */
531 cl_git_pass(git_repository_open_from_worktree(&repo, wt));
532
533 git_worktree_free(wt);
534 git_repository_free(repo);
535 }
536
537 void test_worktree_worktree__prune_valid(void)
538 {
539 git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
540 git_worktree *wt;
541 git_repository *repo;
542
543 opts.flags = GIT_WORKTREE_PRUNE_VALID;
544
545 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
546 cl_git_pass(git_worktree_prune(wt, &opts));
547
548 /* Assert the repository is not valid anymore */
549 cl_git_fail(git_repository_open_from_worktree(&repo, wt));
550
551 git_worktree_free(wt);
552 git_repository_free(repo);
553 }
554
555 void test_worktree_worktree__prune_locked(void)
556 {
557 git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
558 git_worktree *wt;
559 git_repository *repo;
560
561 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
562 cl_git_pass(git_worktree_lock(wt, NULL));
563
564 opts.flags = GIT_WORKTREE_PRUNE_VALID;
565 cl_git_fail(git_worktree_prune(wt, &opts));
566 /* Assert the repository is still valid */
567 cl_git_pass(git_repository_open_from_worktree(&repo, wt));
568
569 opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_LOCKED;
570 cl_git_pass(git_worktree_prune(wt, &opts));
571
572 git_worktree_free(wt);
573 git_repository_free(repo);
574 }
575
576 void test_worktree_worktree__prune_gitdir_only(void)
577 {
578 git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
579 git_worktree *wt;
580
581 opts.flags = GIT_WORKTREE_PRUNE_VALID;
582 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
583 cl_git_pass(git_worktree_prune(wt, &opts));
584
585 cl_assert(!git_fs_path_exists(wt->gitdir_path));
586 cl_assert(git_fs_path_exists(wt->gitlink_path));
587
588 git_worktree_free(wt);
589 }
590
591 void test_worktree_worktree__prune_worktree(void)
592 {
593 git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
594 git_worktree *wt;
595
596 opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_WORKING_TREE;
597
598 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
599 cl_git_pass(git_worktree_prune(wt, &opts));
600
601 cl_assert(!git_fs_path_exists(wt->gitdir_path));
602 cl_assert(!git_fs_path_exists(wt->gitlink_path));
603
604 git_worktree_free(wt);
605 }
606
607 static int foreach_worktree_cb(git_repository *worktree, void *payload)
608 {
609 int *counter = (int *)payload;
610
611 switch (*counter) {
612 case 0:
613 cl_assert_equal_s(git_repository_path(fixture.repo),
614 git_repository_path(worktree));
615 cl_assert(!git_repository_is_worktree(worktree));
616 break;
617 case 1:
618 cl_assert_equal_s(git_repository_path(fixture.worktree),
619 git_repository_path(worktree));
620 cl_assert(git_repository_is_worktree(worktree));
621 break;
622 default:
623 cl_fail("more worktrees found than expected");
624 }
625
626 (*counter)++;
627
628 return 0;
629 }
630
631 void test_worktree_worktree__foreach_worktree_lists_all_worktrees(void)
632 {
633 int counter = 0;
634 cl_git_pass(git_repository_foreach_worktree(fixture.repo, foreach_worktree_cb, &counter));
635 }
636
637 void test_worktree_worktree__validate_invalid_worktreedir(void)
638 {
639 git_worktree *wt;
640
641 cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
642 p_rename("testrepo-worktree", "testrepo-worktree-tmp");
643 cl_git_fail(git_worktree_validate(wt));
644 p_rename("testrepo-worktree-tmp", "testrepo-worktree");
645
646 git_worktree_free(wt);
647 }