summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/refs/head.py2
-rw-r--r--git/refs/symbolic.py6
-rw-r--r--git/repo/base.py5
-rw-r--r--test/test_refs.py9
4 files changed, 14 insertions, 8 deletions
diff --git a/git/refs/head.py b/git/refs/head.py
index 338efce9..4b9bf33c 100644
--- a/git/refs/head.py
+++ b/git/refs/head.py
@@ -142,7 +142,7 @@ class Head(Reference):
flag = "-D"
repo.git.branch(flag, *heads)
- def set_tracking_branch(self, remote_reference: 'RemoteReference') -> 'Head':
+ def set_tracking_branch(self, remote_reference: Union['RemoteReference', None]) -> 'Head':
"""
Configure this branch to track the given remote reference. This will alter
this branch's configuration accordingly.
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 0e9dad5c..9a5a4479 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -28,6 +28,7 @@ from git.types import Commit_ish, PathLike, TBD, Literal
if TYPE_CHECKING:
from git.repo import Repo
+ from git.refs import Reference
T_References = TypeVar('T_References', bound='SymbolicReference')
@@ -356,8 +357,9 @@ class SymbolicReference(object):
return self
# aliased reference
- reference = property(_get_reference, set_reference, doc="Returns the Reference we point to")
- ref: Union[Commit_ish] = reference # type: ignore # Union[str, Commit_ish, SymbolicReference]
+ reference: Union[Commit_ish, 'Reference'] = property( # type: ignore
+ _get_reference, set_reference, doc="Returns the Reference we point to")
+ ref = reference
def is_valid(self):
"""
diff --git a/git/repo/base.py b/git/repo/base.py
index f8a1689a..74f27b2e 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -422,7 +422,7 @@ class Repo(object):
def create_head(self, path: PathLike, commit: str = 'HEAD',
force: bool = False, logmsg: Optional[str] = None
- ) -> 'SymbolicReference':
+ ) -> 'Head':
"""Create a new head within the repository.
For more documentation, please see the Head.create method.
@@ -788,9 +788,8 @@ class Repo(object):
return proc.replace("\\\\", "\\").replace('"', "").split("\n")
@property
- def active_branch(self) -> 'SymbolicReference':
+ def active_branch(self) -> 'HEAD':
"""The name of the currently active branch.
-
:return: Head to the active branch"""
return self.head.reference
diff --git a/test/test_refs.py b/test/test_refs.py
index 1315f885..6f158bee 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -4,6 +4,7 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+from git.repo.base import Repo
from itertools import chain
from git import (
@@ -125,11 +126,15 @@ class TestRefs(TestBase):
gp_tracking_branch = rwrepo.create_head('gp_tracking#123')
special_name_remote_ref = rwrepo.remotes[0].refs[special_name] # get correct type
gp_tracking_branch.set_tracking_branch(special_name_remote_ref)
- assert gp_tracking_branch.tracking_branch().path == special_name_remote_ref.path
+ TBranch = gp_tracking_branch.tracking_branch()
+ if TBranch is not None:
+ assert TBranch.path == special_name_remote_ref.path
git_tracking_branch = rwrepo.create_head('git_tracking#123')
rwrepo.git.branch('-u', special_name_remote_ref.name, git_tracking_branch.name)
- assert git_tracking_branch.tracking_branch().name == special_name_remote_ref.name
+ TBranch = gp_tracking_branch.tracking_branch()
+ if TBranch is not None:
+ assert TBranch.name == special_name_remote_ref.name
# END for each head
# verify REFLOG gets altered