{"thread":{"id":"54366","subject":"git clean -X deletes ignored directory","startedAt":"2020-10-07T19:41:03Z","lastAt":"2020-10-07T19:41:03Z","messageCount":1,"participants":["Yves Fischer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"407090","messageId":"995c4c10c68d39e84aa48ae967f81da6@xapek.org","threadId":"54366","inReplyTo":null,"subject":"git clean -X deletes ignored directory","fromName":"Yves Fischer","fromEmail":"yvesf@xapek.org","sentAt":"2020-10-07T19:32:22Z","receivedAt":"2020-10-07T19:41:03Z","isPatch":false,"sender":{"key":"yvesf@xapek.org","avatar":null},"body":"Hello everyone,\n\nI found a behavior with git-clean that appears to be unexpected.\n\nIt is related to the change in 95c11ec which, if I read the history correctly, got later corrected in cada730.\n\nExample (in git repo after build):\n======\n./git init test\ncd test\nmkdir ignored-subdir\ntouch test.c test.o ignored-subdir/some-file\necho \\*.o > .gitignore\necho ignored-subdir >> .gitignore \n../git add .\n../git commit -m test\n../git clean -X -d -n '*.o'\n# Would remove ignored-subdir/  <--- why?\n# Would remove test.o\n======\n\nIn the example I would have expected that the \"ignored-subdir\" is not deleted because it's not matched by the path argument. The manpage of git-clean says:\n> If any optional <path>... arguments are given, only those paths are affected.\n\nI believe the issue is fixed in cada730 only for files. It seems to persist for directories.\n\nThe attached diff has a test that tries to cover this.\n\nKind regards,\nYves\n\n----\n\ndiff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\nindex cb5e34d94c..77d834d34a 100755\n--- a/t/t7300-clean.sh\n+++ b/t/t7300-clean.sh\n@@ -746,4 +746,49 @@ test_expect_success 'clean untracked paths by pathspec' '\n        test_must_be_empty actual\n '\n \n+# fixed by cada730\n+test_expect_success 'git clean x1' '\n+\n+       git init clean-x1 &&\n+       touch clean-x1/test.c clean-x1/test.o clean-x1/other-untracked-file &&\n+       echo \\*.o >> clean-x1/.gitignore &&\n+       echo other-untracked-file >> clean-x1/.gitignore &&\n+       git -C clean-x1 add . &&\n+       git -C clean-x1 commit -m setup &&\n+       git -C clean-x1 clean -X -d -f \"*.o\" &&\n+       ! test -f clean-x1/test.o &&\n+       test -f clean-x1/other-untracked-file\n+\n+'\n+\n+# fixed by cada730\n+test_expect_success 'git clean x2' '\n+\n+       git init clean-x2 &&\n+       touch clean-x2/test.c clean-x2/test.o clean-x2/other-untracked-file &&\n+       echo \\*.o >> clean-x2/.gitignore &&\n+       echo other-untracked-file >> clean-x2/.gitignore &&\n+       git -C clean-x2 add . &&\n+       git -C clean-x2 commit -m setup &&\n+       git -C clean-x2 clean -X -f \"*.o\" &&\n+       ! test -f clean-x2/test.o &&\n+       test -f clean-x2/other-untracked-file\n+\n+'\n+\n+test_expect_success 'git clean x3' '\n+\n+       git init clean-x3 &&\n+       mkdir other-untracked-dir &&\n+       touch clean-x3/test.c clean-x3/test.o clean-x3/other-untracked-dir/foo &&\n+       echo \\*.o >> clean-x3/.gitignore &&\n+       echo other-untracked-dir >> clean-x3/.gitignore &&\n+       git -C clean-x3 add . &&\n+       git -C clean-x3 commit -m setup &&\n+       git -C clean-x3 clean -X -f \"*.o\" &&\n+       ! test -f clean-x3/test.o &&\n+       test -f clean-x3/other-untracked-dir/foo\n+\n+'\n+\n test_done\n"}]}