### _Black_
+- Respect `.gitignore` files in all levels, not only `root/.gitignore` file (apply
+ `.gitignore` rules like `git` does) (#2225)
- Restored compatibility with Click 8.0 on Python 3.6 when LANG=C used (#2227)
### _Blackd_
## .gitignore
If `--exclude` is not set, _Black_ will automatically ignore files and directories in
-`.gitignore` file, if present. The `.gitignore` file must be in the project root to be
-used and nested `.gitignore` aren't supported.
+`.gitignore` file(s), if present.
If you want _Black_ to continue using `.gitignore` while also configuring the exclusion
rules, please use `--extend-exclude`.
continue
if child.is_dir():
+ # If gitignore is None, gitignore usage is disabled, while a Falsey
+ # gitignore is when the directory doesn't have a .gitignore file.
yield from gen_python_files(
child.iterdir(),
root,
extend_exclude,
force_exclude,
report,
- gitignore,
+ gitignore + get_gitignore(child) if gitignore is not None else None,
)
elif child.is_file():
)
self.assertEqual(sorted(expected), sorted(sources))
- def test_gitingore_used_as_default(self) -> None:
+ def test_gitignore_used_as_default(self) -> None:
path = Path(THIS_DIR / "data" / "include_exclude_tests")
include = re.compile(r"\.pyi?$")
extend_exclude = re.compile(r"/exclude/")
)
self.assertEqual(sorted(expected), sorted(sources))
+ def test_nested_gitignore(self) -> None:
+ path = Path(THIS_DIR / "data" / "nested_gitignore_tests")
+ include = re.compile(r"\.pyi?$")
+ exclude = re.compile(r"")
+ root_gitignore = black.files.get_gitignore(path)
+ report = black.Report()
+ expected: List[Path] = [
+ Path(path / "x.py"),
+ Path(path / "root/b.py"),
+ Path(path / "root/c.py"),
+ Path(path / "root/child/c.py"),
+ ]
+ this_abs = THIS_DIR.resolve()
+ sources = list(
+ black.gen_python_files(
+ path.iterdir(),
+ this_abs,
+ include,
+ exclude,
+ None,
+ None,
+ report,
+ root_gitignore,
+ )
+ )
+ self.assertEqual(sorted(expected), sorted(sources))
+
def test_empty_include(self) -> None:
path = THIS_DIR / "data" / "include_exclude_tests"
report = black.Report()