File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -561,7 +561,7 @@ 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 , "" )
564
+ relative_path = osp . relpath ( path , self .repo .working_tree_dir )
565
565
if relative_path == path :
566
566
raise ValueError ("Absolute path %r is not in git repository at %r" % (path , self .repo .working_tree_dir ))
567
567
return relative_path
Original file line number Diff line number Diff line change @@ -838,6 +838,13 @@ 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
+ class Mocked (Object ):
844
+ repo .working_tree_dir = root
845
+ path = os .path .join (root , 'file' )
846
+ IndexFile ._to_relative_path (Mocked (), path )
847
+
841
848
@with_rw_repo ('HEAD' , bare = True )
842
849
def test_pre_commit_hook_success (self , rw_repo ):
843
850
index = rw_repo .index
You can’t perform that action at this time.
0 commit comments