Skip to content

Commit

Permalink
Merge pull request #1761 from mjpieters/issues/1760
Browse files Browse the repository at this point in the history
Avoid git octal escaping
  • Loading branch information
timothycrosley authored Jun 22, 2021
2 parents fe2735a + 05a8ded commit 15234f8
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Defines how the default settings for isort should be loaded
"""
import codecs
import configparser
import fnmatch
import glob
Expand Down Expand Up @@ -537,31 +536,31 @@ def is_supported_filetype(self, file_name: str) -> bool:
return bool(_SHEBANG_RE.match(line))

def _check_folder_gitignore(self, folder: str) -> Optional[Path]:
env = {"LANG": "C.UTF-8"}
try:
topfolder_result = subprocess.check_output( # nosec # skipcq: PYL-W1510
["git", "-C", folder, "rev-parse", "--show-toplevel"]
["git", "-C", folder, "rev-parse", "--show-toplevel"], encoding="utf-8", env=env
)
git_folder = Path(topfolder_result.decode("utf-8").split("\n")[0])

files = glob.glob(str(git_folder) + "/**/*", recursive=True)
files_result = (
codecs.escape_decode( # type: ignore
subprocess.check_output( # nosec # skipcq: PYL-W1510
["git", "-C", str(git_folder), "check-ignore", "--stdin"],
input="\n".join(files).encode(),
)
)[0]
.decode("utf-8")
.splitlines()
)

self.git_ignore[git_folder] = {Path(f.strip('"')) for f in files_result}
except subprocess.CalledProcessError:
return None

return git_folder
git_folder = Path(topfolder_result.rstrip())

files = glob.glob(f"{git_folder}/**/*", recursive=True)
git_options = ["-C", str(git_folder), "-c", "core.quotePath="]
try:
ignored = subprocess.check_output( # nosec # skipcq: PYL-W1510
["git", *git_options, "check-ignore", "-z", "--stdin"],
encoding="utf-8",
env=env,
input="\0".join(files),
)
except subprocess.CalledProcessError:
return None

self.git_ignore[git_folder] = {Path(f) for f in ignored.rstrip("\0").split("\0")}
return git_folder

def is_skipped(self, file_path: Path) -> bool:
"""Returns True if the file and/or folder should be skipped based on current settings."""
if self.directory and Path(self.directory) in file_path.resolve().parents:
Expand Down

0 comments on commit 15234f8

Please sign in to comment.