Skip to content

Commit

Permalink
Merge pull request #976 from mdagaro/develop
Browse files Browse the repository at this point in the history
Issue #960: Respect .gitignore
  • Loading branch information
timothycrosley authored Jul 22, 2020
2 parents 060571c + b37951a commit 67930e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ def _build_arg_parser() -> argparse.ArgumentParser:
dest="skip_glob",
action="append",
)
parser.add_argument(
"--gitignore",
"--skip-gitignore",
action="store_true",
dest="skip_gitignore",
help="Treat project as a git respository and ignore files listed in .gitignore"
)
inline_args_group.add_argument(
"--sl",
"--force-single-line-imports",
Expand Down
9 changes: 8 additions & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import posixpath
import re
import subprocess
import sys
from functools import lru_cache
from pathlib import Path
Expand Down Expand Up @@ -109,6 +110,7 @@ class _Config:
}
)
skip_glob: FrozenSet[str] = frozenset()
skip_gitignore: bool = False
line_length: int = 79
wrap_length: int = 0
line_ending: str = ""
Expand Down Expand Up @@ -371,6 +373,11 @@ def is_skipped(self, file_path: Path) -> bool:
file_name = str(file_path)

os_path = str(file_path)

if self.skip_gitignore:
result = subprocess.run(['git', 'check-ignore', '--quiet', os_path])
if result.returncode == 0:
return True

normalized_path = os_path.replace("\\", "/")
if normalized_path[1:2] == ":":
Expand Down Expand Up @@ -588,7 +595,7 @@ def _get_config_data(file_path: str, sections: Tuple[str]) -> Dict[str, Any]:

return settings


def _as_bool(value: str) -> bool:
"""Given a string value that represents True or False, returns the Boolean equivalent.
Heavily inspired from distutils strtobool.
Expand Down

0 comments on commit 67930e1

Please sign in to comment.