mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-03 05:12:56 -05:00
dir: do not traverse mount points
It was already decided inef22148(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 fromef22148. Signed-off-by: Maks Kuznia <makskuznia244@gmail.com>
This commit is contained in:
committed by
Johannes Schindelin
parent
e59744675c
commit
b93f3c7eac
7
dir.c
7
dir.c
@@ -3411,6 +3411,13 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_mount_point(path)) {
|
||||
/* Do not descend and nuke a mount point or junction. */
|
||||
if (kept_up)
|
||||
*kept_up = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
|
||||
dir = opendir(path->buf);
|
||||
if (!dir) {
|
||||
|
||||
@@ -271,4 +271,13 @@ test_expect_success 'move worktree with relative path to absolute path' '
|
||||
test_cmp expect .git/worktrees/absolute/gitdir
|
||||
'
|
||||
|
||||
test_expect_success MINGW 'worktree remove does not traverse mount points' '
|
||||
mkdir target &&
|
||||
>target/dont-remove-me &&
|
||||
git worktree add --detach wt-junction &&
|
||||
cmd //c "mklink /j wt-junction\\mnt target" &&
|
||||
git worktree remove --force wt-junction &&
|
||||
test_path_is_file target/dont-remove-me
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user