Unverified Commit b8450b9f authored by Hadi Alqattan's avatar Hadi Alqattan Committed by GitHub
Browse files

Fix: black only respects the root gitignore. (#2225)

Commit history before merge:

Black now respects .gitignore files in all levels, not only root/.gitignore file
(apply .gitignore rules like git does).

* Fix: typo
* Fix: respect .gitignore files in all levels.
* Add: CHANGELOG note.
* Fix: TypeError: unsupported operand type(s) for +: 'NoneType' and 'PathSpec'
* Update docs.
* Fix: no parent .gitignore
* Add a comment since the if expression is a bit hard to understand
* Update tests - conver no parent .gitignore case.
* Use main's Pipfile.lock instead

  The original changes in Pipfile.lock are whitespace only. The changes
  turned the JSON's file indentation from 4 to 2. Effectively this
  happened: `json.dumps(json.loads(old_pipfile_lock), indent=2) + "\n"`.

  Just using main's Pipfile.lock instead of undoing the changes because
  1) I don't know how to do that easily and quickly, and 2) there's a
  merge conflict.

  Co-authored-by: default avatarRichard Si <63936253+ichard26@users.noreply.github.com>

* Merge remote-tracking branch 'upstream/main' into i1730 …
  
  conflicts for days ay?
parent 60f8bd2c
Loading
Loading
Loading
Loading
+2 −0
Changes for CHANGES.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

### _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_
+1 −2
Changes for docs/usage_and_configuration/file_collection_and_discovery.md: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -30,8 +30,7 @@ then write the above files to `.cache/black/<version>/`.
## .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`.
+3 −1
Changes for src/black/files.py: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -204,6 +204,8 @@ def gen_python_files(
            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,
@@ -212,7 +214,7 @@ def gen_python_files(
                extend_exclude,
                force_exclude,
                report,
                gitignore,
                gitignore + get_gitignore(child) if gitignore is not None else None,
            )

        elif child.is_file():
+3 −0
Changes for tests/data/nested_gitignore_tests/pyproject.toml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
[build-system]
requires = ["setuptools>=41.0", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"
+1 −0
Changes for tests/data/nested_gitignore_tests/root/.gitignore: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
a.py
Loading