X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/2704dc796b49b4c5d348c92ba14ef1cfd908e7f1..0e9d29ab73d608a79028e22a713ee717b5dcca96:/src/black/__init__.py?ds=sidebyside diff --git a/src/black/__init__.py b/src/black/__init__.py index 9459227..6c8d346 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -30,6 +30,7 @@ from typing import ( import click from click.core import ParameterSource from mypy_extensions import mypyc_attr +from pathspec import PathSpec from pathspec.patterns.gitwildmatch import GitWildMatchPatternError from _black_version import version as __version__ @@ -627,6 +628,11 @@ def get_sources( sources: Set[Path] = set() root = ctx.obj["root"] + exclude_is_None = exclude is None + exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) if exclude is None else exclude + gitignore = None # type: Optional[PathSpec] + root_gitignore = get_gitignore(root) + for s in src: if s == "-" and stdin_filename: p = Path(stdin_filename) @@ -660,16 +666,14 @@ def get_sources( sources.add(p) elif p.is_dir(): - if exclude is None: - exclude = re_compile_maybe_verbose(DEFAULT_EXCLUDES) - gitignore = get_gitignore(root) + if exclude_is_None: 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 + if root_gitignore == p_gitignore: + gitignore = root_gitignore + else: + gitignore = root_gitignore + p_gitignore sources.update( gen_python_files( p.iterdir(),