Skip to content

Commit

Permalink
Fix: respect .gitignore files in all levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadialqattan committed May 11, 2021
1 parent 86fb1fd commit 81b2589
Show file tree
Hide file tree
Showing 11 changed files with 1,351 additions and 1,317 deletions.
2,632 changes: 1,316 additions & 1,316 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/black/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def gen_python_files(
extend_exclude,
force_exclude,
report,
gitignore,
gitignore + get_gitignore(child),
)

elif child.is_file():
Expand Down
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignored_in_root.py
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/child_dir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignored_in_child.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be excluded
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be excluded
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/child_dir/included.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be included
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/ignored_in_child.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be included
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/ignored_in_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be excluded
1 change: 1 addition & 0 deletions tests/data/gitignore_levels_tests/included.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# should be included
26 changes: 26 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,32 @@ def test_gitignore_exclude(self) -> None:
)
self.assertEqual(sorted(expected), sorted(sources))

def test_respect_gitignore_levels(self) -> None:
path = Path(THIS_DIR / "data" / "gitignore_levels_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 / "included.py"),
Path(path / "ignored_in_child.py"),
Path(path / "child_dir/included.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()
Expand Down

0 comments on commit 81b2589

Please sign in to comment.