diff options
| author | Patrick Steinhardt <ps@pks.im> | 2020-06-17 14:09:04 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2020-07-12 18:12:16 +0200 |
| commit | 2fcb4f2801ef9a1e74b4281a78deae5e25b0ad43 (patch) | |
| tree | 956f69765ded9973b8453950b02d0b34a05d61a1 /tests | |
| parent | d6c62852076005053be9169cb4f3cd9cf9db2aea (diff) | |
| download | libgit2-2fcb4f2801ef9a1e74b4281a78deae5e25b0ad43.tar.gz | |
repository: introduce new function to iterate over all worktrees
Given a Git repository, it's non-trivial to iterate over all worktrees
that are associated with it, including the "main" repository. This
commit adds a new internal function `git_repository_foreach_worktree`
that does this for us.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/worktree/worktree.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index 716d0aa0a..a08c305bc 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -623,3 +623,33 @@ void test_worktree_worktree__foreach_head_gives_same_results_in_wt_and_repo(void git_vector_free(&repo_refs); git_vector_free(&worktree_refs); } + +static int foreach_worktree_cb(git_repository *worktree, void *payload) +{ + int *counter = (int *)payload; + + switch (*counter) { + case 0: + cl_assert_equal_s(git_repository_path(fixture.repo), + git_repository_path(worktree)); + cl_assert(!git_repository_is_worktree(worktree)); + break; + case 1: + cl_assert_equal_s(git_repository_path(fixture.worktree), + git_repository_path(worktree)); + cl_assert(git_repository_is_worktree(worktree)); + break; + default: + cl_fail("more worktrees found than expected"); + } + + (*counter)++; + + return 0; +} + +void test_worktree_worktree__foreach_worktree_lists_all_worktrees(void) +{ + int counter = 0; + cl_git_pass(git_repository_foreach_worktree(fixture.repo, foreach_worktree_cb, &counter)); +} |
