Skip to content

Commit 045748b

Browse files
authored
Merge pull request libgit2#5692 from rbmclean/master
Add missing worktree_dir check and test case
2 parents a6d151b + c8fe4da commit 045748b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/worktree.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ int git_worktree_validate(const git_worktree *wt)
259259
wt->commondir_path);
260260
return GIT_ERROR;
261261
}
262-
262+
263+
if (!git_path_exists(wt->worktree_path)) {
264+
git_error_set(GIT_ERROR_WORKTREE,
265+
"worktree directory '%s' does not exist",
266+
wt->worktree_path);
267+
return GIT_ERROR;
268+
}
269+
263270
return 0;
264271
}
265272

tests/worktree/worktree.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,15 @@ void test_worktree_worktree__foreach_worktree_lists_all_worktrees(void)
610610
int counter = 0;
611611
cl_git_pass(git_repository_foreach_worktree(fixture.repo, foreach_worktree_cb, &counter));
612612
}
613+
614+
void test_worktree_worktree__validate_invalid_worktreedir(void)
615+
{
616+
git_worktree *wt;
617+
618+
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
619+
p_rename("testrepo-worktree", "testrepo-worktree-tmp");
620+
cl_git_fail(git_worktree_validate(wt));
621+
p_rename("testrepo-worktree-tmp", "testrepo-worktree");
622+
623+
git_worktree_free(wt);
624+
}

0 commit comments

Comments
 (0)