| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d3aff0 commit 221defb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ | |||
| 26 | 26 | from git.compat import defenc, safe_decode | |
| 27 | 27 | from git.config import GitConfigParser | |
| 28 | 28 | from git.db import GitCmdObjectDB | |
| 29 | + from git.diff import _unquote_path | ||
| 29 | 30 | from git.exc import ( | |
| 30 | 31 | GitCommandError, | |
| 31 | 32 | InvalidGitRepositoryError, | |
@@ -1158,7 +1159,7 @@ def ignored(self, *paths: PathLike) -> List[str]: | |||
| 1158 | 1159 | Subset of those paths which are ignored | |
| 1159 | 1160 | """ | |
| 1160 | 1161 | try: | |
| 1161 | - proc: str = self.git.check_ignore("--", *paths) | ||
| 1162 | + proc: bytes = self.git.check_ignore("--", *paths, stdout_as_string=False) | ||
| 1162 | 1163 | except GitCommandError as err: | |
| 1163 | 1164 | if err.status == 1: | |
| 1164 | 1165 | # If return code is 1, this means none of the items in *paths are | |
@@ -1168,7 +1169,12 @@ def ignored(self, *paths: PathLike) -> List[str]: | |||
| 1168 | 1169 | # Raise the exception on all other return codes. | |
| 1169 | 1170 | raise | |
| 1170 | 1171 | ||
| 1171 | - return proc.replace("\\\\", "\\").replace('"', "").split("\n") | ||
| 1172 | + # Git C-quotes a path containing special characters, including a line feed, | ||
| 1173 | + # so each path is on its own line. | ||
| 1174 | + return [ | ||
| 1175 | + safe_decode(_unquote_path(path[1:-1]) if path[:1] == path[-1:] == b'"' else path) | ||
| 1176 | + for path in proc.split(b"\n") | ||
| 1177 | + ] | ||
| 1172 | 1178 | ||
| 1173 | 1179 | @property | |
| 1174 | 1180 | def active_branch(self) -> Head: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1657,6 +1657,17 @@ def test_ignored_items_reported(self): | |||
| 1657 | 1657 | ["included_file.txt", "ignored_file.txt", "included_dir/file.txt", "ignored_dir/file.txt"] | |
| 1658 | 1658 | ) == ["ignored_file.txt", "ignored_dir/file.txt"] | |
| 1659 | 1659 | ||
| 1660 | + def test_ignored_items_reported_verbatim(self): | ||
| 1661 | + with tempfile.TemporaryDirectory() as tdir: | ||
| 1662 | + temp_repo = Repo.init(pathlib.Path(tdir) / "repo") | ||
| 1663 | + | ||
| 1664 | + with open(pathlib.Path(temp_repo.working_tree_dir) / ".gitignore", "w") as file: | ||
| 1665 | + file.write("*.env\n") | ||
| 1666 | + | ||
| 1667 | + # Git C-quotes each of these in its default output format. | ||
| 1668 | + paths = ["donn\u00e9es.env", 'q"uote.env', "tab\t.env", "nl\nx.env"] | ||
| 1669 | + assert temp_repo.ignored(["keep.txt", *paths]) == paths | ||
| 1670 | + | ||
| 1660 | 1671 | @requires_symlinks | |
| 1661 | 1672 | def test_ignored_raises_error_w_symlink(self): | |
| 1662 | 1673 | with tempfile.TemporaryDirectory() as tdir: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments