summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/worktree/refs.c5
-rw-r--r--tests/worktree/submodule.c2
-rw-r--r--tests/worktree/worktree.c76
3 files changed, 69 insertions, 14 deletions
diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c
index 95b173ef5..a10f50a2c 100644
--- a/tests/worktree/refs.c
+++ b/tests/worktree/refs.c
@@ -118,11 +118,14 @@ void test_worktree_refs__delete_fails_for_checked_out_branch(void)
void test_worktree_refs__delete_succeeds_after_pruning_worktree(void)
{
+ git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_reference *branch;
git_worktree *worktree;
+ opts.flags = GIT_WORKTREE_PRUNE_VALID;
+
cl_git_pass(git_worktree_lookup(&worktree, fixture.repo, fixture.worktreename));
- cl_git_pass(git_worktree_prune(worktree, GIT_WORKTREE_PRUNE_VALID));
+ cl_git_pass(git_worktree_prune(worktree, &opts));
git_worktree_free(worktree);
cl_git_pass(git_branch_lookup(&branch, fixture.repo,
diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c
index 562077597..294385226 100644
--- a/tests/worktree/submodule.c
+++ b/tests/worktree/submodule.c
@@ -74,7 +74,7 @@ void test_worktree_submodule__resolve_relative_url(void)
cl_git_pass(git_repository_open(&child.repo, WORKTREE_CHILD));
/* Create worktree of submodule repository */
- cl_git_pass(git_worktree_add(&wt, child.repo, "subdir", wt_path.ptr));
+ cl_git_pass(git_worktree_add(&wt, child.repo, "subdir", wt_path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&repo, wt));
cl_git_pass(git_submodule_resolve_url(&sm_relative_path, repo,
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 73991bff7..4ac3b8bba 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -215,7 +215,7 @@ void test_worktree_worktree__init(void)
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
- cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr));
+ cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Open and verify created repo */
cl_git_pass(git_repository_open(&repo, path.ptr));
@@ -228,6 +228,31 @@ void test_worktree_worktree__init(void)
git_repository_free(repo);
}
+void test_worktree_worktree__add_locked(void)
+{
+ git_worktree *wt;
+ git_repository *repo;
+ git_reference *branch;
+ git_buf path = GIT_BUF_INIT;
+ git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
+
+ opts.lock = 1;
+
+ cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
+ cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
+
+ /* Open and verify created repo */
+ cl_assert(git_worktree_is_locked(NULL, wt));
+ cl_git_pass(git_repository_open(&repo, path.ptr));
+ cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
+ cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
+
+ git_buf_free(&path);
+ git_worktree_free(wt);
+ git_reference_free(branch);
+ git_repository_free(repo);
+}
+
void test_worktree_worktree__init_existing_branch(void)
{
git_reference *head, *branch;
@@ -240,7 +265,7 @@ void test_worktree_worktree__init_existing_branch(void)
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
- cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr));
+ cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
git_buf_free(&path);
git_commit_free(commit);
@@ -254,7 +279,7 @@ void test_worktree_worktree__init_existing_worktree(void)
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
- cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr));
+ cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
@@ -279,7 +304,7 @@ void test_worktree_worktree__init_existing_path(void)
}
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
- cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr));
+ cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
@@ -303,7 +328,7 @@ void test_worktree_worktree__init_submodule(void)
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
cl_git_pass(git_repository_open(&sm, path.ptr));
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
- cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr));
+ cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
cl_git_pass(git_path_prettify_dir(&path, path.ptr, NULL));
@@ -429,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));
@@ -446,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));
@@ -474,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));