Skip to content

Commit 7efb1fc

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Don't traverse mount points in remove_dir_recurse() (#6151)
`remove_dir_recurse()` in `dir.c` doesn't check for mount points, even though this check was already added for `git clean` in #2268. So `git worktree remove` (or anything else that calls it) will traverse NTFS junctions and delete whatever is there. Similar to #607. This extends the same check from #2268 but for anything that calls `remove_dir_recurse()`.
2 parents 3255d0a + 8e0ee91 commit 7efb1fc

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)