summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/worktree.c3
-rwxr-xr-xt/t2026-worktree-prune.sh7
2 files changed, 5 insertions, 5 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 60440c4106..b1e8f0534c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -100,7 +100,8 @@ static int prune_worktree(const char *id, struct strbuf *reason)
path[len] = '\0';
if (!file_exists(path)) {
free(path);
- if (st.st_mtime <= expire) {
+ if (stat(git_path("worktrees/%s/index", id), &st) ||
+ st.st_mtime <= expire) {
strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
return 1;
} else {
diff --git a/t/t2026-worktree-prune.sh b/t/t2026-worktree-prune.sh
index a0f1e3bb80..b7d6d5d45a 100755
--- a/t/t2026-worktree-prune.sh
+++ b/t/t2026-worktree-prune.sh
@@ -78,10 +78,9 @@ test_expect_success 'not prune locked checkout' '
test_expect_success 'not prune recent checkouts' '
test_when_finished rm -r .git/worktrees &&
- mkdir zz &&
- mkdir -p .git/worktrees/jlm &&
- echo "$(pwd)"/zz >.git/worktrees/jlm/gitdir &&
- rmdir zz &&
+ git worktree add jlm HEAD &&
+ test -d .git/worktrees/jlm &&
+ rm -rf jlm &&
git worktree prune --verbose --expire=2.days.ago &&
test -d .git/worktrees/jlm
'