Skip to content

pathspec v1 changes #4944

@cpburnz

Description

@cpburnz

Is your feature request related to a problem? Please describe.

Hi, I'm the author of pathspec, and recently released v1. The biggest change is GitWildMatchPattern (a.k.a. "gitwildmatch") was split into two different implementations. (1) GitIgnoreBasicPattern (a.k.a. "gitignore") is new and properly implements the patterns in gitignore's documentation. (2) GitIgnoreSpecPattern is the previous GitWildMatchPattern implementation and is used by GitIgnoreSpec to implement Git's edge-cases.

PathSpec

The form PathSpec.from_lines('gitwildmatch', ...) is now deprecated because it does not fully match the behavior of the gitignore docs or Git itself. There's 3 possible replacements depending on the exact behavior you want:

  1. To keep the exact behavior as before, use PathSpec.from_lines(GitIgnoreSpecPattern, ...). This is the non-deprecated equivalent to using "gitwildmatch". I discourage this use because it's a hybrid between Git's behavior and the gitignore docs.

    from pathspec.patterns.gitignore.spec import GitIgnoreSpecPattern
  2. To follow the gitignore docs, use PathSpec.from_lines('gitignore', ...). The change for using this form is "foo/*" will no longer match files in subdirectories, and the exact pattern "/" is equivalent to "**" (match everything) rather than being a no-op.

  3. To follow Git's implementation, use GitIgnoreSpec.from_lines(...). The change for using this is Git allows including files from excluded directories which directly contradicts the gitignore docs.

return PathSpec.from_lines("gitwildmatch", lines)

black/tests/test_black.py

Lines 2517 to 2519 in c3cc5a9

gitignore = PathSpec.from_lines(
"gitwildmatch", ["exclude/", ".definitely_exclude"]
)

gitignore = PathSpec.from_lines("gitwildmatch", [])

GitIgnorePatternError

pathspec.patterns.gitwildmatch.GitWildMatchPatternError is now a deprecated alias of pathspec.patterns.gitignore.GitIgnorePatternError. I recommend switching to GitIgnorePatternError.

from pathspec.patterns.gitwildmatch import GitWildMatchPatternError

from pathspec.patterns.gitwildmatch import GitWildMatchPatternError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions