|
8 | 8 | #define COMMON_REPO "testrepo" |
9 | 9 | #define WORKTREE_REPO "testrepo-worktree" |
10 | 10 |
|
| 11 | +static void assert_worktree_valid(git_repository *wt, const char *parentdir, const char *wtdir) |
| 12 | +{ |
| 13 | + git_buf path = GIT_BUF_INIT; |
| 14 | + |
| 15 | + cl_assert(wt->is_worktree); |
| 16 | + |
| 17 | + cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), wtdir)); |
| 18 | + cl_git_pass(git_path_prettify(&path, path.ptr, NULL)); |
| 19 | + cl_git_pass(git_path_to_dir(&path)); |
| 20 | + cl_assert_equal_s(wt->workdir, path.ptr); |
| 21 | + |
| 22 | + cl_git_pass(git_buf_joinpath(&path, path.ptr, ".git")); |
| 23 | + cl_git_pass(git_path_prettify(&path, path.ptr, NULL)); |
| 24 | + cl_assert_equal_s(wt->gitlink, path.ptr); |
| 25 | + |
| 26 | + cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), parentdir)); |
| 27 | + cl_git_pass(git_buf_joinpath(&path, path.ptr, ".git")); |
| 28 | + cl_git_pass(git_buf_joinpath(&path, path.ptr, "worktrees")); |
| 29 | + cl_git_pass(git_buf_joinpath(&path, path.ptr, wtdir)); |
| 30 | + cl_git_pass(git_path_prettify(&path, path.ptr, NULL)); |
| 31 | + cl_git_pass(git_path_to_dir(&path)); |
| 32 | + cl_assert_equal_s(wt->gitdir, path.ptr); |
| 33 | + |
| 34 | + git_buf_free(&path); |
| 35 | +} |
| 36 | + |
11 | 37 | void test_worktree_open__repository(void) |
12 | 38 | { |
13 | 39 | worktree_fixture fixture = |
14 | 40 | WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO); |
15 | 41 | setup_fixture_worktree(&fixture); |
16 | 42 |
|
17 | | - cl_assert(git_repository_path(fixture.worktree) != NULL); |
18 | | - cl_assert(git_repository_workdir(fixture.worktree) != NULL); |
| 43 | + assert_worktree_valid(fixture.worktree, COMMON_REPO, WORKTREE_REPO); |
19 | 44 |
|
20 | | - cl_assert(!fixture.repo->is_worktree); |
21 | | - cl_assert(fixture.worktree->is_worktree); |
| 45 | + cleanup_fixture_worktree(&fixture); |
| 46 | +} |
| 47 | + |
| 48 | +void test_worktree_open__repository_through_workdir(void) |
| 49 | +{ |
| 50 | + worktree_fixture fixture = |
| 51 | + WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO); |
| 52 | + git_repository *wt; |
| 53 | + |
| 54 | + setup_fixture_worktree(&fixture); |
| 55 | + |
| 56 | + cl_git_pass(git_repository_open(&wt, WORKTREE_REPO)); |
| 57 | + assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO); |
| 58 | + |
| 59 | + git_repository_free(wt); |
| 60 | + cleanup_fixture_worktree(&fixture); |
| 61 | +} |
| 62 | + |
| 63 | +void test_worktree_open__repository_through_gitlink(void) |
| 64 | +{ |
| 65 | + worktree_fixture fixture = |
| 66 | + WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO); |
| 67 | + git_repository *wt; |
| 68 | + |
| 69 | + setup_fixture_worktree(&fixture); |
| 70 | + |
| 71 | + cl_git_pass(git_repository_open(&wt, WORKTREE_REPO "/.git")); |
| 72 | + assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO); |
| 73 | + |
| 74 | + git_repository_free(wt); |
| 75 | + cleanup_fixture_worktree(&fixture); |
| 76 | +} |
| 77 | + |
| 78 | +void test_worktree_open__repository_through_gitdir(void) |
| 79 | +{ |
| 80 | + worktree_fixture fixture = |
| 81 | + WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO); |
| 82 | + git_buf gitdir_path = GIT_BUF_INIT; |
| 83 | + git_repository *wt; |
| 84 | + |
| 85 | + setup_fixture_worktree(&fixture); |
| 86 | + |
| 87 | + cl_git_pass(git_buf_joinpath(&gitdir_path, COMMON_REPO, ".git")); |
| 88 | + cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees")); |
| 89 | + cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree")); |
| 90 | + |
| 91 | + cl_git_pass(git_repository_open(&wt, gitdir_path.ptr)); |
| 92 | + assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO); |
22 | 93 |
|
| 94 | + git_buf_free(&gitdir_path); |
| 95 | + git_repository_free(wt); |
23 | 96 | cleanup_fixture_worktree(&fixture); |
24 | 97 | } |
25 | 98 |
|
|
0 commit comments