3333from .enums import DiffOption , FileMode
3434from .errors import check_error
3535from .ffi import C , ffi
36- from .utils import GenericIterator , StrArray , decode_fs_path , encode_fs_path
36+ from .utils import (
37+ GenericIterator ,
38+ StrArray ,
39+ decode_fs_path ,
40+ encode_fs_path ,
41+ encode_git_path ,
42+ )
3743
3844if typing .TYPE_CHECKING :
3945 from .repository import Repository
@@ -79,7 +85,7 @@ def __len__(self) -> int:
7985 return C .git_index_entrycount (self ._index )
8086
8187 def __contains__ (self , path ) -> bool :
82- err = C .git_index_find (ffi .NULL , self ._index , encode_fs_path (path ))
88+ err = C .git_index_find (ffi .NULL , self ._index , encode_git_path (path ))
8389 if err == C .GIT_ENOTFOUND :
8490 return False
8591
@@ -89,7 +95,7 @@ def __contains__(self, path) -> bool:
8995 def __getitem__ (self , key : str | int | PathLike [str ]) -> 'IndexEntry' :
9096 centry = ffi .NULL
9197 if isinstance (key , str ) or hasattr (key , '__fspath__' ):
92- centry = C .git_index_get_bypath (self ._index , encode_fs_path (key ), 0 )
98+ centry = C .git_index_get_bypath (self ._index , encode_git_path (key ), 0 )
9399 elif isinstance (key , int ):
94100 if key >= 0 :
95101 centry = C .git_index_get_byindex (self ._index , key )
@@ -180,12 +186,12 @@ def write_tree(self, repo: 'Repository | None' = None) -> Oid:
180186
181187 def remove (self , path : PathLike [str ] | str , level : int = 0 ) -> None :
182188 """Remove an entry from the Index."""
183- err = C .git_index_remove (self ._index , encode_fs_path (path ), level )
189+ err = C .git_index_remove (self ._index , encode_git_path (path ), level )
184190 check_error (err , io = True )
185191
186192 def remove_directory (self , path : PathLike [str ] | str , level : int = 0 ) -> None :
187193 """Remove a directory from the Index."""
188- err = C .git_index_remove_directory (self ._index , encode_fs_path (path ), level )
194+ err = C .git_index_remove_directory (self ._index , encode_git_path (path ), level )
189195 check_error (err , io = True )
190196
191197 def remove_all (self , pathspecs : typing .Sequence [str | PathLike [str ]]) -> None :
@@ -221,7 +227,7 @@ def add(self, path_or_entry: 'IndexEntry | str | PathLike[str]') -> None:
221227 err = C .git_index_add (self ._index , centry )
222228 elif isinstance (path_or_entry , str ) or hasattr (path_or_entry , '__fspath__' ):
223229 path = path_or_entry
224- err = C .git_index_add_bypath (self ._index , encode_fs_path (path ))
230+ err = C .git_index_add_bypath (self ._index , encode_git_path (path ))
225231 else :
226232 raise TypeError ('argument must be string, Path or IndexEntry' )
227233
@@ -475,7 +481,7 @@ def _to_c(self) -> tuple['ffi.GitIndexEntryC', 'ffi.ArrayC[ffi.char]']:
475481 # basically memcpy()
476482 ffi .buffer (ffi .addressof (centry , 'id' ))[:] = self .id .raw [:]
477483 centry .mode = int (self .mode )
478- path = ffi .new ('char[]' , encode_fs_path (self .path ))
484+ path = ffi .new ('char[]' , encode_git_path (self .path ))
479485 centry .path = path
480486
481487 return centry , path
@@ -503,7 +509,7 @@ def __getitem__(self, path):
503509 ctheirs = ffi .new ('git_index_entry **' )
504510
505511 err = C .git_index_conflict_get (
506- cancestor , cours , ctheirs , self ._index ._index , encode_fs_path (path )
512+ cancestor , cours , ctheirs , self ._index ._index , encode_git_path (path )
507513 )
508514 check_error (err )
509515
@@ -514,7 +520,7 @@ def __getitem__(self, path):
514520 return ancestor , ours , theirs
515521
516522 def __delitem__ (self , path ):
517- err = C .git_index_conflict_remove (self ._index ._index , encode_fs_path (path ))
523+ err = C .git_index_conflict_remove (self ._index ._index , encode_git_path (path ))
518524 check_error (err )
519525
520526 def __iter__ (self ):
@@ -526,7 +532,7 @@ def __contains__(self, path):
526532 ctheirs = ffi .new ('git_index_entry **' )
527533
528534 err = C .git_index_conflict_get (
529- cancestor , cours , ctheirs , self ._index ._index , encode_fs_path (path )
535+ cancestor , cours , ctheirs , self ._index ._index , encode_git_path (path )
530536 )
531537 if err == C .GIT_ENOTFOUND :
532538 return False
0 commit comments