Skip to content

Commit 502c386

Browse files
szedergitster
authored andcommitted
t7300-clean: demonstrate deleting nested repo with an ignored file breakage
'git clean -fd' must not delete an untracked directory if it belongs to a different Git repository or worktree. Unfortunately, if a '.gitignore' rule in the outer repository happens to match a file in a nested repository or worktree, then something goes awry and 'git clean -fd' does delete the content of the nested repository's worktree except that ignored file, potentially leading to data loss. Add a test to 't7300-clean.sh' to demonstrate this breakage. This issue is a regression introduced in 6b1db43 (clean: teach clean -d to preserve ignored paths, 2017-05-23). Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75b2f01 commit 502c386

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

t/t7300-clean.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,28 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
669669
test_path_is_missing foo/b/bb
670670
'
671671

672+
test_expect_failure 'git clean -d skips nested repo containing ignored files' '
673+
test_when_finished "rm -rf nested-repo-with-ignored-file" &&
674+
675+
git init nested-repo-with-ignored-file &&
676+
(
677+
cd nested-repo-with-ignored-file &&
678+
>file &&
679+
git add file &&
680+
git commit -m Initial &&
681+
682+
# This file is ignored by a .gitignore rule in the outer repo
683+
# added in the previous test.
684+
>ignoreme
685+
) &&
686+
687+
git clean -fd &&
688+
689+
test_path_is_file nested-repo-with-ignored-file/.git/index &&
690+
test_path_is_file nested-repo-with-ignored-file/ignoreme &&
691+
test_path_is_file nested-repo-with-ignored-file/file
692+
'
693+
672694
test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
673695
test_config core.longpaths false &&
674696
a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&

0 commit comments

Comments
 (0)