Closed rmcloughlin closed 1 month ago
PR welcome to improve this.
Interestingly, if the content of .gitignore
is set to large_ignored_dir
without a trailing slash, it works as expected:
Found input source directory: "[...]\my-project"
[...]\my-project\large_ignored_dir ignored: matches a .gitignore file content
[...]\my-project\z.py already well formatted, good job.
All done! ✨ 🍰 ✨
1 file would be left unchanged.
So maybe we should add a trailing slash to relative_path
in _path_is_ignored()
if the path is a directory?
Say I have this file structure:
The only file I want black to pay attention to is
z.py
.Then I run
black --exclude='large_ignored_dir/' --check -v .
which shows me:That seems to be the correct behavior.
But black is supposed to automatically ignore directories listed in
.gitignore
(docs). So if I add a.gitignore
file containing this line:Then I should be able to run
black --check -v .
and see the same result as above. But instead I see:Even though the final result is the same (only
z.py
is reformatted), in this second case black is wasting time checking files that it could have skipped. Instead of ignoring all oflarge_ignored_dir
it is descending one level inside it and then deciding to skip every file and subdirectory.This has performance consequences with directories like
node_modules
and__pycache__
.Environment