Commit 848c7793d41a594e7b503fe0bc956b79c95295d6

Reginald McLean 2020-11-06T11:32:13

worktree: Demonstrate missing worktree check worktree_dir isn't validated when it should be

diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index cd20bed..c3abf00 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -610,3 +610,17 @@ 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));
 }
+
+void test_worktree_worktree__validate_invalid_worktreedir(void)
+{
+	git_worktree *wt;
+
+	cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
+	git__free(wt->worktree_path);
+	wt->worktree_path = "/path/to/invalid/worktreedir";
+
+	cl_git_fail(git_worktree_validate(wt));
+
+	wt->worktree_path = NULL;
+	git_worktree_free(wt);
+}