diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-05-02 12:35:59 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-05-05 15:39:25 +0200 |
| commit | 883eeb5f909f230822c0bc025d3f9ce79781de04 (patch) | |
| tree | 957edab7f83315a90e685dfcd4569fb889de0258 /tests/worktree/worktree.c | |
| parent | 8264a30f4fbfce96f433f01fa6fe537e5cb3570d (diff) | |
| download | libgit2-883eeb5f909f230822c0bc025d3f9ce79781de04.tar.gz | |
worktree: switch over worktree pruning to an opts structure
The current signature of `git_worktree_prune` accepts a flags field to
alter its behavior. This is not as flexible as we'd like it to be when
we want to enable passing additional options in the future. As the
function has not been part of any release yet, we are still free to
alter its current signature. This commit does so by using our usual
pattern of an options structure, which is easily extendable without
breaking the API.
Diffstat (limited to 'tests/worktree/worktree.c')
| -rw-r--r-- | tests/worktree/worktree.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index 7ab86cceb..4ac3b8bba 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -454,13 +454,31 @@ void test_worktree_worktree__unlock_locked_worktree(void) git_worktree_free(wt); } +void test_worktree_worktree__prune_without_opts_fails(void) +{ + git_worktree *wt; + git_repository *repo; + + cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); + cl_git_fail(git_worktree_prune(wt, NULL)); + + /* Assert the repository is still valid */ + cl_git_pass(git_repository_open_from_worktree(&repo, wt)); + + git_worktree_free(wt); + git_repository_free(repo); +} + void test_worktree_worktree__prune_valid(void) { + git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; git_worktree *wt; git_repository *repo; + opts.flags = GIT_WORKTREE_PRUNE_VALID; + cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); - cl_git_pass(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_VALID)); + cl_git_pass(git_worktree_prune(wt, &opts)); /* Assert the repository is not valid anymore */ cl_git_fail(git_repository_open_from_worktree(&repo, wt)); @@ -471,27 +489,33 @@ void test_worktree_worktree__prune_valid(void) void test_worktree_worktree__prune_locked(void) { + git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; git_worktree *wt; git_repository *repo; cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); cl_git_pass(git_worktree_lock(wt, NULL)); - cl_git_fail(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_VALID)); - cl_git_fail(git_worktree_prune(wt, ~GIT_WORKTREE_PRUNE_LOCKED)); + opts.flags = GIT_WORKTREE_PRUNE_VALID; + cl_git_fail(git_worktree_prune(wt, &opts)); /* Assert the repository is still valid */ cl_git_pass(git_repository_open_from_worktree(&repo, wt)); + opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_LOCKED; + cl_git_pass(git_worktree_prune(wt, &opts)); + git_worktree_free(wt); git_repository_free(repo); } -void test_worktree_worktree__prune_gitdir(void) +void test_worktree_worktree__prune_gitdir_only(void) { + git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; git_worktree *wt; + opts.flags = GIT_WORKTREE_PRUNE_VALID; cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); - cl_git_pass(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_VALID)); + cl_git_pass(git_worktree_prune(wt, &opts)); cl_assert(!git_path_exists(wt->gitdir_path)); cl_assert(git_path_exists(wt->gitlink_path)); @@ -499,12 +523,15 @@ void test_worktree_worktree__prune_gitdir(void) git_worktree_free(wt); } -void test_worktree_worktree__prune_both(void) +void test_worktree_worktree__prune_worktree(void) { + git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT; git_worktree *wt; + opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_WORKING_TREE; + cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); - cl_git_pass(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_WORKING_TREE | GIT_WORKTREE_PRUNE_VALID)); + cl_git_pass(git_worktree_prune(wt, &opts)); cl_assert(!git_path_exists(wt->gitdir_path)); cl_assert(!git_path_exists(wt->gitlink_path)); |
