@@ -79,7 +79,7 @@ def __init__(self, repo: "Repo", path: PathLike, check_path: bool = False) -> No
7979 self .path = path
8080
8181 def __str__ (self ) -> str :
82- return str (self .path )
82+ return os . fspath (self .path )
8383
8484 def __repr__ (self ) -> str :
8585 return '<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
109109 def abspath (self ) -> PathLike :
@@ -178,7 +178,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
178178 """
179179 previous : Union [str , None ] = None
180180 one_before_previous : Union [str , None ] = None
181- for c in str (ref_path ):
181+ for c in os . fspath (ref_path ):
182182 if c in " ~^:?*[\\ " :
183183 raise ValueError (
184184 f"Invalid reference '{ ref_path } ': references cannot contain spaces, tildes (~), carets (^),"
@@ -212,7 +212,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None:
212212 raise ValueError (f"Invalid reference '{ ref_path } ': references cannot end with a forward slash (/)" )
213213 elif previous == "@" and one_before_previous is None :
214214 raise 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 ("/" )):
216216 raise ValueError (
217217 f"Invalid reference '{ ref_path } ': references cannot have slash-separated components that end with"
218218 " '.lock'"
@@ -235,7 +235,7 @@ def _get_ref_info_helper(
235235 tokens : Union [None , List [str ], Tuple [str , str ]] = None
236236 repodir = _git_dir (repo , ref_path )
237237 try :
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 :
239239 value = 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:
614614 full_ref_path = path
615615 if not cls ._common_path_default :
616616 return full_ref_path
617- if not str (path ).startswith (cls ._common_path_default + "/" ):
617+ if not os . fspath (path ).startswith (cls ._common_path_default + "/" ):
618618 full_ref_path = "%s/%s" % (cls ._common_path_default , path )
619619 return full_ref_path
620620
@@ -706,7 +706,7 @@ def _create(
706706 if not force and os .path .isfile (abs_ref_path ):
707707 target_data = str (target )
708708 if isinstance (target , SymbolicReference ):
709- target_data = str (target .path )
709+ target_data = os . fspath (target .path )
710710 if not resolve :
711711 target_data = "ref: " + target_data
712712 with open (abs_ref_path , "rb" ) as fd :
@@ -842,7 +842,7 @@ def _iter_items(
842842
843843 # Read packed refs.
844844 for _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 )):
846846 rela_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
932932 def 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 + "/" )
0 commit comments