summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-03-15 16:44:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-15 19:37:48 (GMT)
commit327864aaf76d000ee5d7722b9b9611ed7a2708f5 (patch)
tree088d930ae49158c06e836499537a863c5ff7516a /builtin/worktree.c
parent3800135b8955cd9bf43c8599e6d41774a0e8e986 (diff)
downloadgit-327864aaf76d000ee5d7722b9b9611ed7a2708f5.zip
git-327864aaf76d000ee5d7722b9b9611ed7a2708f5.tar.gz
git-327864aaf76d000ee5d7722b9b9611ed7a2708f5.tar.bz2
worktree prune: improve prune logic when worktree is moved
Automatic detection of worktree relocation by a user (via 'mv', for instance) was removed by 618244e160 (worktree: stop supporting moving worktrees manually - 2016-01-22). Prior to that, .git/worktrees/<tag>/gitdir was updated whenever the worktree was accessed in order to let the pruning logic know that the worktree was "active" even if it disappeared for a while (due to being located on removable media, for instance). "git worktree move" has come so we don't really need this, but since it's easy to do, perhaps we could keep supporting manual worktree move a bit longer. Notice that when a worktree is active, the "index" file should be updated pretty often in common case. The logic is updated to check for index mtime to see if the worktree is alive. The old logic of checking gitdir's mtime is dropped because nobody updates it anyway. The new corner case is, if the index file does not exist, we immediately remove the stale worktree. But if the "index" file does not exist, you may have a bigger problem. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 60440c4..b1e8f05 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 {