FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(repo): unquote `git check-ignore` paths in `Repo.ignored` by Keerthana-64 · Pull Request #2298 · gitpython-developers/GitPython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions git/repo/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from git.compat import defenc, safe_decode
from git.config import GitConfigParser
from git.db import GitCmdObjectDB
from git.diff import _unquote_path
from git.exc import (
GitCommandError,
InvalidGitRepositoryError,
Expand Down Expand Up @@ -1158,7 +1159,7 @@ def ignored(self, *paths: PathLike) -> List[str]:
Subset of those paths which are ignored
"""
try:
proc: str = self.git.check_ignore("--", *paths)
proc: bytes = self.git.check_ignore("--", *paths, stdout_as_string=False)
except GitCommandError as err:
if err.status == 1:
# If return code is 1, this means none of the items in *paths are
Expand All @@ -1168,7 +1169,12 @@ def ignored(self, *paths: PathLike) -> List[str]:
# Raise the exception on all other return codes.
raise

return proc.replace("\\\\", "\\").replace('"', "").split("\n")
# Git C-quotes a path containing special characters, including a line feed,
# so each path is on its own line.
return [
safe_decode(_unquote_path(path[1:-1]) if path[:1] == path[-1:] == b'"' else path)
for path in proc.split(b"\n")
]

@property
def active_branch(self) -> Head:
Expand Down
11 changes: 11 additions & 0 deletions test/test_repo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,17 @@ def test_ignored_items_reported(self):
["included_file.txt", "ignored_file.txt", "included_dir/file.txt", "ignored_dir/file.txt"]
) == ["ignored_file.txt", "ignored_dir/file.txt"]

def test_ignored_items_reported_verbatim(self):
with tempfile.TemporaryDirectory() as tdir:
temp_repo = Repo.init(pathlib.Path(tdir) / "repo")

with open(pathlib.Path(temp_repo.working_tree_dir) / ".gitignore", "w") as file:
file.write("*.env\n")

# Git C-quotes each of these in its default output format.
paths = ["donn\u00e9es.env", 'q"uote.env', "tab\t.env", "nl\nx.env"]
assert temp_repo.ignored(["keep.txt", *paths]) == paths

@requires_symlinks
def test_ignored_raises_error_w_symlink(self):
with tempfile.TemporaryDirectory() as tdir:
Expand Down
Loading

Back | FazBrowse Home | New Git URL