@@ -79,7 +79,7 @@ def __init__(self, repo: "Repo", path: PathLike, check_path: bool = False) -> No
7979self .path = path
8080
8181def __str__ (self )-> str :
82- return str (self .path )
82+ return os . fspath (self .path )
8383
8484def __repr__ (self )-> str :
8585return '<git.%s "%s">' % (self .__class__ .__name__ ,self .path )
@@ -103,7 +103,7 @@ def name(self) -> str:
103103 In case of symbolic references, the shortest assumable name is the path
104104 itself.
105105 """
106- return str (self .path )
106+ return os . fspath (self .path )
107107
108108@property
109109def abspath (self )-> PathLike :
@@ -178,7 +178,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
178178 """
179179previous :Union [str ,None ]= None
180180one_before_previous :Union [str ,None ]= None
181- for c in str (ref_path ):
181+ for c in os . fspath (ref_path ):
182182if c in " ~^:?*[\\ " :
183183raise ValueError (
184184f"Invalid reference '{ ref_path } ': references cannot contain spaces, tildes (~), carets (^),"
@@ -212,7 +212,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
212212raise ValueError (f"Invalid reference '{ ref_path } ': references cannot end with a forward slash (/)" )
213213elif previous == "@" and one_before_previous is None :
214214raise ValueError (f"Invalid reference '{ ref_path } ': references cannot be '@'" )
215- elif any (component .endswith (".lock" )for component in str (ref_path ).split ("/" )):
215+ elif any (component .endswith (".lock" )for component in os . fspath (ref_path ).split ("/" )):
216216raise ValueError (
217217f"Invalid reference '{ ref_path } ': references cannot have slash-separated components that end with"
218218" '.lock'"
@@ -235,7 +235,7 @@ def _get_ref_info_helper(
235235tokens :Union [None ,List [str ],Tuple [str ,str ]]= None
236236repodir = _git_dir (repo ,ref_path )
237237try :
238- with open (os .path .join (repodir ,str (ref_path )),"rt" ,encoding = "UTF-8" )as fp :
238+ with open (os .path .join (repodir ,os . fspath (ref_path )),"rt" ,encoding = "UTF-8" )as fp :
239239value = fp .read ().rstrip ()
240240# Don't only split on spaces, but on whitespace, which allows to parse lines like:
241241# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -614,7 +614,7 @@ def to_full_path(cls, path: Union[PathLike, "SymbolicReference"]) -> PathLike:
614614full_ref_path = path
615615if not cls ._common_path_default :
616616return full_ref_path
617- if not str (path ).startswith (cls ._common_path_default + "/" ):
617+ if not os . fspath (path ).startswith (cls ._common_path_default + "/" ):
618618full_ref_path = "%s/%s" % (cls ._common_path_default ,path )
619619return full_ref_path
620620
@@ -706,7 +706,7 @@ def _create(
706706if not force and os .path .isfile (abs_ref_path ):
707707target_data = str (target )
708708if isinstance (target ,SymbolicReference ):
709- target_data = str (target .path )
709+ target_data = os . fspath (target .path )
710710if not resolve :
711711target_data = "ref: " + target_data
712712with open (abs_ref_path ,"rb" )as fd :
@@ -842,7 +842,7 @@ def _iter_items(
842842
843843# Read packed refs.
844844for _sha ,rela_path in cls ._iter_packed_refs (repo ):
845- if rela_path .startswith (str (common_path )):
845+ if rela_path .startswith (os . fspath (common_path )):
846846rela_paths .add (rela_path )
847847# END relative path matches common path
848848# END packed refs reading
@@ -931,4 +931,4 @@ def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_Refere
931931
932932def is_remote (self )-> bool :
933933""":return: True if this symbolic reference points to a remote branch"""
934- return str (self .path ).startswith (self ._remote_common_path_default + "/" )
934+ return os . fspath (self .path ).startswith (self ._remote_common_path_default + "/" )