Skip to content

Hopefully fixes Orderedict error #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Install dependencies and prepare tests
run: |
set -x
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

python -m pip install --upgrade pip setuptools wheel
python --version; git --version
git submodule update --init --recursive
Expand Down
11 changes: 6 additions & 5 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@

T_ConfigParser = TypeVar('T_ConfigParser', bound='GitConfigParser')

if sys.version_info[:2] < (3, 7):
from collections import OrderedDict
OrderedDict_OMD = OrderedDict
if sys.version_info[:3] < (3, 7, 2):
# typing.Ordereddict not added until py 3.7.2
from collections import OrderedDict # type: ignore # until 3.6 dropped
OrderedDict_OMD = OrderedDict # type: ignore # until 3.6 dropped
else:
from typing import OrderedDict
OrderedDict_OMD = OrderedDict[str, List[_T]]
from typing import OrderedDict # type: ignore # until 3.6 dropped
OrderedDict_OMD = OrderedDict[str, List[_T]] # type: ignore[assignment, misc]

# -------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, tree: Union[Tree, None] = None,
as what time.altzone returns. The sign is inverted compared to git's
UTC timezone."""
super(Commit, self).__init__(repo, binsha)
self.binsha = binsha
if tree is not None:
assert isinstance(tree, Tree), "Tree needs to be a Tree instance, was %s" % type(tree)
if tree is not None:
Expand Down
8 changes: 5 additions & 3 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def update(self, recursive: bool = False, init: bool = True, to_latest_revision:
progress.update(op, i, len_rmts, prefix + "Done fetching remote of submodule %r" % self.name)
# END fetch new data
except InvalidGitRepositoryError:
mrepo = None
if not init:
return self
# END early abort if init is not allowed
Expand Down Expand Up @@ -603,7 +604,7 @@ def update(self, recursive: bool = False, init: bool = True, to_latest_revision:

# make sure HEAD is not detached
mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch)
mrepo.head.ref.set_tracking_branch(remote_branch)
mrepo.head.reference.set_tracking_branch(remote_branch)
except (IndexError, InvalidGitRepositoryError):
log.warning("Failed to checkout tracking branch %s", self.branch_path)
# END handle tracking branch
Expand All @@ -629,13 +630,14 @@ def update(self, recursive: bool = False, init: bool = True, to_latest_revision:
if mrepo is not None and to_latest_revision:
msg_base = "Cannot update to latest revision in repository at %r as " % mrepo.working_dir
if not is_detached:
rref = mrepo.head.ref.tracking_branch()
rref = mrepo.head.reference.tracking_branch()
if rref is not None:
rcommit = rref.commit
binsha = rcommit.binsha
hexsha = rcommit.hexsha
else:
log.error("%s a tracking branch was not set for local branch '%s'", msg_base, mrepo.head.ref)
log.error("%s a tracking branch was not set for local branch '%s'",
msg_base, mrepo.head.reference)
# END handle remote ref
else:
log.error("%s there was no local tracking branch", msg_base)
Expand Down
5 changes: 5 additions & 0 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TI
return super(TraversableIterableObj, self)._list_traverse(* args, **kwargs)

@ overload # type: ignore
def traverse(self: T_TIobj
) -> Iterator[T_TIobj]:
...

@ overload
def traverse(self: T_TIobj,
predicate: Callable[[Union[T_TIobj, Tuple[Union[T_TIobj, None], T_TIobj]], int], bool],
prune: Callable[[Union[T_TIobj, Tuple[Union[T_TIobj, None], T_TIobj]], int], bool],
Expand Down
15 changes: 8 additions & 7 deletions git/refs/head.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from git.config import SectionConstraint
from git.config import GitConfigParser, SectionConstraint
from git.util import join_path
from git.exc import GitCommandError

Expand Down Expand Up @@ -142,7 +142,7 @@ def delete(cls, repo: 'Repo', *heads: 'Head', **kwargs: Any):
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.
Expand Down Expand Up @@ -203,7 +203,7 @@ def rename(self, new_path: PathLike, force: bool = False) -> 'Head':
self.path = "%s/%s" % (self._common_path_default, new_path)
return self

def checkout(self, force: bool = False, **kwargs: Any):
def checkout(self, force: bool = False, **kwargs: Any) -> Union['HEAD', 'Head']:
"""Checkout this head by setting the HEAD to this reference, by updating the index
to reflect the tree we point to and by updating the working tree to reflect
the latest index.
Expand Down Expand Up @@ -235,10 +235,11 @@ def checkout(self, force: bool = False, **kwargs: Any):
self.repo.git.checkout(self, **kwargs)
if self.repo.head.is_detached:
return self.repo.head
return self.repo.active_branch
else:
return self.repo.active_branch

#{ Configuration
def _config_parser(self, read_only: bool) -> SectionConstraint:
def _config_parser(self, read_only: bool) -> SectionConstraint[GitConfigParser]:
if read_only:
parser = self.repo.config_reader()
else:
Expand All @@ -247,13 +248,13 @@ def _config_parser(self, read_only: bool) -> SectionConstraint:

return SectionConstraint(parser, 'branch "%s"' % self.name)

def config_reader(self) -> SectionConstraint:
def config_reader(self) -> SectionConstraint[GitConfigParser]:
"""
:return: A configuration parser instance constrained to only read
this instance's values"""
return self._config_parser(read_only=True)

def config_writer(self) -> SectionConstraint:
def config_writer(self) -> SectionConstraint[GitConfigParser]:
"""
:return: A configuration writer instance with read-and write access
to options of this head"""
Expand Down
4 changes: 3 additions & 1 deletion git/refs/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def __str__(self) -> str:

#{ Interface

def set_object(self, object: Commit_ish, logmsg: Union[str, None] = None) -> 'Reference': # @ReservedAssignment
# @ReservedAssignment
def set_object(self, object: Union[Commit_ish, 'SymbolicReference'], logmsg: Union[str, None] = None
) -> 'SymbolicReference':
"""Special version which checks if the head-log needs an update as well
:return: self"""
oldbinsha = None
Expand Down
Loading