| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dc7ba87 commit 11f7faf
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -655,7 +655,10 @@ def _to_relative_path(self, path: PathLike) -> PathLike: | |||
| 655 | 655 | raise InvalidGitRepositoryError("require non-bare repository") | |
| 656 | 656 | if not osp.normpath(str(path)).startswith(str(self.repo.working_tree_dir)): | |
| 657 | 657 | raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir)) | |
| 658 | - return os.path.relpath(path, self.repo.working_tree_dir) | ||
| 658 | + result = os.path.relpath(path, self.repo.working_tree_dir) | ||
| 659 | + if str(path).endswith(os.sep) and not result.endswith(os.sep): | ||
| 660 | + result += os.sep | ||
| 661 | + return result | ||
| 659 | 662 | ||
| 660 | 663 | def _preprocess_add_items( | |
| 661 | 664 | self, items: Union[PathLike, Sequence[Union[PathLike, Blob, BaseIndexEntry, "Submodule"]]] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | import subprocess | |
| 17 | 17 | import sys | |
| 18 | 18 | import tempfile | |
| 19 | + from unittest import mock | ||
| 19 | 20 | ||
| 20 | 21 | from gitdb.base import IStream | |
| 21 | 22 | ||
@@ -1015,6 +1016,27 @@ class Mocked: | |||
| 1015 | 1016 | rel = index._to_relative_path(path) | |
| 1016 | 1017 | self.assertEqual(rel, os.path.relpath(path, root)) | |
| 1017 | 1018 | ||
| 1019 | + def test__to_relative_path_absolute_trailing_slash(self): | ||
| 1020 | + repo_root = os.path.join(osp.abspath(os.sep), "directory1", "repo_root") | ||
| 1021 | + | ||
| 1022 | + class Mocked: | ||
| 1023 | + bare = False | ||
| 1024 | + git_dir = repo_root | ||
| 1025 | + working_tree_dir = repo_root | ||
| 1026 | + | ||
| 1027 | + repo = Mocked() | ||
| 1028 | + path = os.path.join(repo_root, f"directory2{os.sep}") | ||
| 1029 | + index = IndexFile(repo) | ||
| 1030 | + | ||
| 1031 | + expected_path = f"directory2{os.sep}" | ||
| 1032 | + actual_path = index._to_relative_path(path) | ||
| 1033 | + self.assertEqual(expected_path, actual_path) | ||
| 1034 | + | ||
| 1035 | + with mock.patch("git.index.base.os.path") as ospath_mock: | ||
| 1036 | + ospath_mock.relpath.return_value = f"directory2{os.sep}" | ||
| 1037 | + actual_path = index._to_relative_path(path) | ||
| 1038 | + self.assertEqual(expected_path, actual_path) | ||
| 1039 | + | ||
| 1018 | 1040 | @pytest.mark.xfail( | |
| 1019 | 1041 | type(_win_bash_status) is WinBashStatus.Absent, | |
| 1020 | 1042 | reason="Can't run a hook on Windows without bash.exe.", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments