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 6b1db43109 (clean: teach clean -d to preserve ignored paths, 2017-05-23). Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Aug 25, 2019 at 20:59 UTC 502c386ff944898c1327a5b5a0fefcd4f62d613a
1 file changed +22
t/t7300-clean.sh
+22
@@ -669,6 +669,28 @@ test_expect_success 'git clean -d skips untracked dirs containing ignored files'
669 test_path_is_missing foo/b/bb
670 '
671
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 +
694 test_expect_success MINGW 'handle clean & core.longpaths = false nicely' '
695 test_config core.longpaths false &&
696 a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&