2525
2626if TYPE_CHECKING :
2727 from git .repo import Repo
28- from git .refs import Reference , Head , HEAD , TagReference , RemoteReference
28+ from git .refs import Reference , Head , TagReference , RemoteReference
2929
3030T_References = TypeVar ('T_References' , bound = 'SymbolicReference' )
3131
@@ -60,6 +60,7 @@ class SymbolicReference(object):
6060 def __init__ (self , repo : 'Repo' , path : PathLike , check_path : bool = False ) -> None :
6161 self .repo = repo
6262 self .path = str (path )
63+ self .ref = self ._get_reference ()
6364
6465 def __str__ (self ) -> str :
6566 return self .path
@@ -279,7 +280,7 @@ def set_object(self, object, logmsg=None): # @ReservedAssignment
279280 object = property (_get_object , set_object , doc = "Return the object our ref currently refers to" )
280281
281282 def _get_reference (self
282- ) -> Union ['HEAD' , ' Head' , 'RemoteReference' , 'TagReference' , 'Reference' , 'SymbolicReference ' ]:
283+ ) -> Union ['Head' , 'RemoteReference' , 'TagReference' , 'Reference' ]:
283284 """:return: Reference Object we point to
284285 :raise TypeError: If this symbolic reference is detached, hence it doesn't point
285286 to a reference, but to a commit"""
@@ -288,7 +289,8 @@ def _get_reference(self
288289 raise TypeError ("%s is a detached symbolic reference as it points to %r" % (self , sha ))
289290 return self .from_path (self .repo , target_ref_path )
290291
291- def set_reference (self , ref , logmsg = None ):
292+ def set_reference (self , ref : Union [str , Commit_ish , 'SymbolicReference' ], logmsg : Union [str , None ] = None
293+ ) -> None :
292294 """Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
293295 Otherwise an Object, given as Object instance or refspec, is assumed and if valid,
294296 will be set which effectively detaches the refererence if it was a purely
@@ -355,12 +357,16 @@ def set_reference(self, ref, logmsg=None):
355357 if logmsg is not None :
356358 self .log_append (oldbinsha , logmsg )
357359
358- return self
360+ return None
359361
360- # aliased reference
361- reference : Union [Commit_ish , 'Head' , 'Reference' ] = property ( # type: ignore
362- _get_reference , set_reference , doc = "Returns the Reference we point to" )
363- ref = reference
362+ @ property
363+ def reference (self ) -> Union ['Head' , 'RemoteReference' , 'TagReference' , 'Reference' ]:
364+ return self ._get_reference ()
365+
366+ @ reference .setter
367+ def reference (self , ref : Union [str , Commit_ish , 'SymbolicReference' ], logmsg : Union [str , None ] = None
368+ ) -> None :
369+ return self .set_reference (ref = ref , logmsg = logmsg )
364370
365371 def is_valid (self ) -> bool :
366372 """
@@ -374,7 +380,7 @@ def is_valid(self) -> bool:
374380 else :
375381 return True
376382
377- @property
383+ @ property
378384 def is_detached (self ):
379385 """
380386 :return:
@@ -424,7 +430,7 @@ def log_entry(self, index):
424430 In that case, it will be faster than the ``log()`` method"""
425431 return RefLog .entry_at (RefLog .path (self ), index )
426432
427- @classmethod
433+ @ classmethod
428434 def to_full_path (cls , path : Union [PathLike , 'SymbolicReference' ]) -> str :
429435 """
430436 :return: string with a full repository-relative path which can be used to initialize
@@ -439,7 +445,7 @@ def to_full_path(cls, path: Union[PathLike, 'SymbolicReference']) -> str:
439445 full_ref_path = '%s/%s' % (cls ._common_path_default , path )
440446 return full_ref_path
441447
442- @classmethod
448+ @ classmethod
443449 def delete (cls , repo : 'Repo' , path : PathLike ) -> None :
444450 """Delete the reference at the given path
445451
@@ -497,8 +503,10 @@ def delete(cls, repo: 'Repo', path: PathLike) -> None:
497503 os .remove (reflog_path )
498504 # END remove reflog
499505
500- @classmethod
501- def _create (cls , repo , path , resolve , reference , force , logmsg = None ):
506+ @ classmethod
507+ def _create (cls : Type [T_References ], repo : 'Repo' , path : PathLike , resolve : bool ,
508+ reference : Union [str , 'SymbolicReference' ],
509+ force : bool , logmsg : Union [str , None ] = None ) -> T_References :
502510 """internal method used to create a new symbolic reference.
503511 If resolve is False, the reference will be taken as is, creating
504512 a proper symbolic reference. Otherwise it will be resolved to the
@@ -531,8 +539,9 @@ def _create(cls, repo, path, resolve, reference, force, logmsg=None):
531539 return ref
532540
533541 @classmethod
534- def create (cls , repo : 'Repo' , path : PathLike , reference : Union [Commit_ish , str ] = 'SymbolicReference' ,
535- logmsg : Union [str , None ] = None , force : bool = False , ** kwargs : Any ):
542+ def create (cls : Type [T_References ], repo : 'Repo' , path : PathLike ,
543+ reference : Union [Commit_ish , str , 'SymbolicReference' ] = 'SymbolicReference' ,
544+ logmsg : Union [str , None ] = None , force : bool = False , ** kwargs : Any ) -> T_References :
536545 """Create a new symbolic reference, hence a reference pointing , to another reference.
537546
538547 :param repo:
@@ -669,7 +678,7 @@ def iter_items(cls, repo: 'Repo', common_path: Union[PathLike, None] = None, *ar
669678 return (r for r in cls ._iter_items (repo , common_path ) if r .__class__ == SymbolicReference or not r .is_detached )
670679
671680 @classmethod
672- def from_path (cls , repo , path ) :
681+ def from_path (cls , repo : 'Repo' , path : PathLike ) -> Union [ 'Head' , 'RemoteReference' , 'TagReference' , 'Reference' ] :
673682 """
674683 :param path: full .git-directory-relative path name to the Reference to instantiate
675684 :note: use to_full_path() if you only have a partial path of a known Reference Type
0 commit comments