| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -561,10 +561,9 @@ def _to_relative_path(self, path): | |||
| 561 | 561 | return path | |
| 562 | 562 | if self.repo.bare: | |
| 563 | 563 | raise InvalidGitRepositoryError("require non-bare repository") | |
| 564 | - relative_path = path.replace(self.repo.working_tree_dir + os.sep, "") | ||
| 565 | - if relative_path == path: | ||
| 564 | + if not path.startswith(self.repo.working_tree_dir): | ||
| 566 | 565 | raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir)) | |
| 567 | - return relative_path | ||
| 566 | + return os.path.relpath(path, self.repo.working_tree_dir) | ||
| 568 | 567 | ||
| 569 | 568 | def _preprocess_add_items(self, items): | |
| 570 | 569 | """ Split the items into two lists of path strings and BaseEntries. """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -838,6 +838,21 @@ def test_add_a_file_with_wildcard_chars(self, rw_dir): | |||
| 838 | 838 | r.index.add([fp]) | |
| 839 | 839 | r.index.commit('Added [.exe') | |
| 840 | 840 | ||
| 841 | + def test__to_relative_path_at_root(self): | ||
| 842 | + root = osp.abspath(os.sep) | ||
| 843 | + | ||
| 844 | + class Mocked(object): | ||
| 845 | + bare = False | ||
| 846 | + git_dir = root | ||
| 847 | + working_tree_dir = root | ||
| 848 | + | ||
| 849 | + repo = Mocked() | ||
| 850 | + path = os.path.join(root, 'file') | ||
| 851 | + index = IndexFile(repo) | ||
| 852 | + | ||
| 853 | + rel = index._to_relative_path(path) | ||
| 854 | + self.assertEqual(rel, os.path.relpath(path, root)) | ||
| 855 | + | ||
| 841 | 856 | @with_rw_repo('HEAD', bare=True) | |
| 842 | 857 | def test_pre_commit_hook_success(self, rw_repo): | |
| 843 | 858 | index = rw_repo.index | |
| Back | FazBrowse Home | New Git URL |
0 commit comments