diff options
| author | Patrick Steinhardt <ps@pks.im> | 2015-10-21 13:53:18 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-02-13 11:02:03 +0100 |
| commit | f0cfc34105fd68af9eb6e2024459c40c45e7d3a0 (patch) | |
| tree | f8487a9f042180a253e79fcc6be7c19a744b2f5f /tests/worktree/worktree.c | |
| parent | 2a503485fae6c93c76bd0465c8b3fad5d9e19f6d (diff) | |
| download | libgit2-f0cfc34105fd68af9eb6e2024459c40c45e7d3a0.tar.gz | |
worktree: implement `git_worktree_prune`
Implement the `git_worktree_prune` function. This function can be
used to delete working trees from a repository. According to the
flags passed to it, it can either delete the working tree's
gitdir only or both gitdir and the working directory.
Diffstat (limited to 'tests/worktree/worktree.c')
| -rw-r--r-- | tests/worktree/worktree.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index 82b4ebc0d..7758b1b1c 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -395,3 +395,61 @@ void test_worktree_worktree__unlock_locked_worktree(void) git_worktree_free(wt); } + +void test_worktree_worktree__prune_valid(void) +{ + git_worktree *wt; + git_repository *repo; + + cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); + cl_git_pass(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_VALID)); + + /* Assert the repository is not valid anymore */ + cl_git_fail(git_repository_open_from_worktree(&repo, wt)); + + git_worktree_free(wt); + git_repository_free(repo); +} + +void test_worktree_worktree__prune_locked(void) +{ + 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)); + + /* 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_gitdir(void) +{ + git_worktree *wt; + + cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); + cl_git_pass(git_worktree_prune(wt, GIT_WORKTREE_PRUNE_VALID)); + + cl_assert(!git_path_exists(wt->gitdir_path)); + cl_assert(git_path_exists(wt->gitlink_path)); + + git_worktree_free(wt); +} + +void test_worktree_worktree__prune_both(void) +{ + git_worktree *wt; + + 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_assert(!git_path_exists(wt->gitdir_path)); + cl_assert(!git_path_exists(wt->gitlink_path)); + + git_worktree_free(wt); +} |
