]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Use .gitignore files in the initial source directories (#3237)
authorMartin de La Gorce <martin.delagorce@gmail.com>
Wed, 31 Aug 2022 19:47:42 +0000 (20:47 +0100)
committerGitHub <noreply@github.com>
Wed, 31 Aug 2022 19:47:42 +0000 (15:47 -0400)
Solves https://github.com/psf/black/issues/2598 where Black wouldn't
use .gitignore at folder/.gitignore if you ran `black folder` for
example.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
CHANGES.md
src/black/__init__.py
tests/test_black.py

index a5ce3b1fbe217d6d8c53e3fc384e17ec18a21416..6aa81a8f5c2404dd0cc8f2fb6bafb5bf2b420b74 100644 (file)
@@ -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
 
index 86a0b63744264c85dc23f8702768d333c047f221..ded4a7368228949c1ec43448c7fc241e0604f10b 100644 (file)
@@ -653,6 +653,11 @@ def get_sources(
             if exclude is None:
                 exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES)
                 gitignore = get_gitignore(root)
+                p_gitignore = get_gitignore(p)
+                # No need to use p's gitignore if it is identical to root's gitignore
+                # (i.e. root and p point to the same directory).
+                if gitignore != p_gitignore:
+                    gitignore += p_gitignore
             else:
                 gitignore = None
             sources.update(
index 089e043d639a82f9614018dba2b300580544dc30..abd4d00b8e86ab128dcf16e38a8fcfbd054adfb1 100644 (file)
@@ -1990,6 +1990,13 @@ class TestFileCollection:
         )
         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"