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
7778def __init__ (self ,repo :"Repo" ,path :PathLike ,check_path :bool = False )-> None :
7879self .repo = repo
79- self .path = os . fspath ( path )
80+ self .path : PathLike = path
8081
8182def __str__ (self )-> str :
82- return self .path
83+ return os . fspath ( self .path )
8384
8485def __repr__ (self )-> str :
8586return '<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
109110def abspath (self )-> PathLike :
@@ -212,7 +213,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
212213raise ValueError (f"Invalid reference '{ ref_path } ': references cannot end with a forward slash (/)" )
213214elif previous == "@" and one_before_previous is None :
214215raise 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 ):
216217raise ValueError (
217218f"Invalid reference '{ ref_path } ': references cannot have slash-separated components that end with"
218219" '.lock'"
@@ -235,7 +236,7 @@ def _get_ref_info_helper(
235236tokens :Union [None ,List [str ],Tuple [str ,str ]]= None
236237repodir = _git_dir (repo ,ref_path )
237238try :
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 :
239240value = 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(
706707if not force and os .path .isfile (abs_ref_path ):
707708target_data = str (target )
708709if isinstance (target ,SymbolicReference ):
709- target_data = target .path
710+ target_data = os . fspath ( target .path )
710711if not resolve :
711712target_data = "ref: " + target_data
712713with 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
931932def 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 + "/" )