44__all__ = ["SymbolicReference" ]
55
66import os
7+ from pathlib import Path
78
89from gitdb .exc import BadName , BadObject
910
@@ -76,10 +77,10 @@ class SymbolicReference:
7677
7778 def __init__ (self , repo : "Repo" , path : PathLike , check_path : bool = False ) -> None :
7879 self .repo = repo
79- self .path = os . fspath ( path )
80+ self .path : PathLike = path
8081
8182 def __str__ (self ) -> str :
82- return self .path
83+ return os . fspath ( self .path )
8384
8485 def __repr__ (self ) -> str :
8586 return '<git.%s "%s">' % (self .__class__ .__name__ , self .path )
@@ -103,7 +104,7 @@ def name(self) -> str:
103104 In case of symbolic references, the shortest assumable name is the path
104105 itself.
105106 """
106- return self .path
107+ return os . fspath ( self .path )
107108
108109 @property
109110 def abspath (self ) -> PathLike :
@@ -212,7 +213,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
212213 raise ValueError (f"Invalid reference '{ ref_path } ': references cannot end with a forward slash (/)" )
213214 elif previous == "@" and one_before_previous is None :
214215 raise ValueError (f"Invalid reference '{ ref_path } ': references cannot be '@'" )
215- elif any (component .endswith (".lock" ) for component in os . fspath (ref_path ).split ( "/" ) ):
216+ elif any (component .endswith (".lock" ) for component in Path (ref_path ).parts ):
216217 raise ValueError (
217218 f"Invalid reference '{ ref_path } ': references cannot have slash-separated components that end with"
218219 " '.lock'"
@@ -235,7 +236,7 @@ def _get_ref_info_helper(
235236 tokens : Union [None , List [str ], Tuple [str , str ]] = None
236237 repodir = _git_dir (repo , ref_path )
237238 try :
238- with open (os .path .join (repodir , os . fspath ( ref_path ) ), "rt" , encoding = "UTF-8" ) as fp :
239+ with open (os .path .join (repodir , ref_path ), "rt" , encoding = "UTF-8" ) as fp :
239240 value = fp .read ().rstrip ()
240241 # Don't only split on spaces, but on whitespace, which allows to parse lines like:
241242 # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -706,7 +707,7 @@ def _create(
706707 if not force and os .path .isfile (abs_ref_path ):
707708 target_data = str (target )
708709 if isinstance (target , SymbolicReference ):
709- target_data = target .path
710+ target_data = os . fspath ( target .path )
710711 if not resolve :
711712 target_data = "ref: " + target_data
712713 with open (abs_ref_path , "rb" ) as fd :
@@ -930,4 +931,4 @@ def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_Refere
930931
931932 def is_remote (self ) -> bool :
932933 """:return: True if this symbolic reference points to a remote branch"""
933- return self .path .startswith (self ._remote_common_path_default + "/" )
934+ return os . fspath ( self .path ) .startswith (self ._remote_common_path_default + "/" )
0 commit comments