Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0857d33

Browse files
efiopByron
authored andcommitted
git: index: base: use os.path.relpath
Fixes#743Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
1 parente79a3f8 commit0857d33

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎git/index/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,9 @@ def _to_relative_path(self, path):
561561
returnpath
562562
ifself.repo.bare:
563563
raiseInvalidGitRepositoryError("require non-bare repository")
564-
relative_path=path.replace(self.repo.working_tree_dir+os.sep,"")
565-
ifrelative_path==path:
564+
ifnotpath.startswith(self.repo.working_tree_dir):
566565
raiseValueError("Absolute path %r is not in git repository at %r"% (path,self.repo.working_tree_dir))
567-
returnrelative_path
566+
returnos.path.relpath(path,self.repo.working_tree_dir)
568567

569568
def_preprocess_add_items(self,items):
570569
""" Split the items into two lists of path strings and BaseEntries. """

‎git/test/test_index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,21 @@ def test_add_a_file_with_wildcard_chars(self, rw_dir):
838838
r.index.add([fp])
839839
r.index.commit('Added [.exe')
840840

841+
deftest__to_relative_path_at_root(self):
842+
root=osp.abspath(os.sep)
843+
844+
classMocked(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+
841856
@with_rw_repo('HEAD',bare=True)
842857
deftest_pre_commit_hook_success(self,rw_repo):
843858
index=rw_repo.index

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp