Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .gitignore files in the initial source directories #3237

Merged
merged 4 commits into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -44,6 +44,9 @@
- Black now uses the presence of debug f-strings to detect target version. (#3215)
- Fix misdetection of project root and verbose logging of sources in cases involving
`--stdin-filename` (#3216)
- Immediate `.gitignore` files in source directories given on the command line are now
also respected, previously only `.gitignore` files in the project root and
automatically discovered directories were respected (#3237)

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion src/black/__init__.py
Expand Up @@ -652,7 +652,7 @@ def get_sources(
elif p.is_dir():
if exclude is None:
exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES)
gitignore = get_gitignore(root)
gitignore = get_gitignore(root) + get_gitignore(p)
else:
gitignore = None
sources.update(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_black.py
Expand Up @@ -1990,6 +1990,13 @@ def test_nested_gitignore(self) -> None:
)
assert sorted(expected) == sorted(sources)

def test_nested_gitignore_directly_in_source_directory(self) -> None:
# https://github.com/psf/black/issues/2598
path = Path(DATA_DIR / "nested_gitignore_tests")
src = Path(path / "root" / "child")
expected = [src / "a.py", src / "c.py"]
assert_collected_sources([src], expected)

def test_invalid_gitignore(self) -> None:
path = THIS_DIR / "data" / "invalid_gitignore_tests"
empty_config = path / "pyproject.toml"
Expand Down