Skip to content

Commit 17d6da6

Browse files
maks244Git for Windows Build Agent
authored andcommitted
dir: do not traverse mount points
It was already decided in ef22148 (clean: do not traverse mount points, 2018-12-07) that we shouldn't traverse NTFS junctions/bind mounts when using `git clean`, partly because they're sometimes used in worktrees. But the same check wasn't applied to `remove_dir_recurse()` in `dir.c`, which `git worktree remove` uses. So removing a worktree suffers the same problem we had previously with `git clean`. Let's add the same guard from ef22148. Signed-off-by: Maks Kuznia <makskuznia244@gmail.com>
1 parent e18f3f7 commit 17d6da6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

dir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,13 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
34113411
return 0;
34123412
}
34133413

3414+
if (is_mount_point(path)) {
3415+
/* Do not descend and nuke a mount point or junction. */
3416+
if (kept_up)
3417+
*kept_up = 1;
3418+
return 0;
3419+
}
3420+
34143421
flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
34153422
dir = opendir(path->buf);
34163423
if (!dir) {

t/t2403-worktree-move.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,13 @@ test_expect_success 'move worktree with relative path to absolute path' '
271271
test_cmp expect .git/worktrees/absolute/gitdir
272272
'
273273

274+
test_expect_success MINGW 'worktree remove does not traverse mount points' '
275+
mkdir target &&
276+
>target/dont-remove-me &&
277+
git worktree add --detach wt-junction &&
278+
cmd //c "mklink /j wt-junction\\mnt target" &&
279+
git worktree remove --force wt-junction &&
280+
test_path_is_file target/dont-remove-me
281+
'
282+
274283
test_done

0 commit comments

Comments
 (0)