Skip to content

Commit 451504f

Browse files
committed
fix(remote): lazy PushInfo.old_commit initialization
We will now populate the old_commit on demand, which will allow us to keep going even if the given commit does not exist locally. Fixes #461
1 parent f128ae9 commit 451504f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

git/remote.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def to_progress_instance(progress):
7777

7878

7979
class PushInfo(object):
80-
8180
"""
8281
Carries information about the result of a push operation of a single head::
8382
@@ -92,7 +91,7 @@ class PushInfo(object):
9291
# it to local_ref.commit. Will be None if an error was indicated
9392
info.summary # summary line providing human readable english text about the push
9493
"""
95-
__slots__ = ('local_ref', 'remote_ref_string', 'flags', 'old_commit', '_remote', 'summary')
94+
__slots__ = ('local_ref', 'remote_ref_string', 'flags', '_old_commit_sha', '_remote', 'summary')
9695

9796
NEW_TAG, NEW_HEAD, NO_MATCH, REJECTED, REMOTE_REJECTED, REMOTE_FAILURE, DELETED, \
9897
FORCED_UPDATE, FAST_FORWARD, UP_TO_DATE, ERROR = [1 << x for x in range(11)]
@@ -112,8 +111,12 @@ def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit=None,
112111
self.local_ref = local_ref
113112
self.remote_ref_string = remote_ref_string
114113
self._remote = remote
115-
self.old_commit = old_commit
114+
self._old_commit_sha = old_commit
116115
self.summary = summary
116+
117+
@property
118+
def old_commit(self):
119+
return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None
117120

118121
@property
119122
def remote_ref(self):
@@ -176,7 +179,7 @@ def _from_line(cls, remote, line):
176179
split_token = ".."
177180
old_sha, new_sha = summary.split(' ')[0].split(split_token)
178181
# have to use constructor here as the sha usually is abbreviated
179-
old_commit = remote.repo.commit(old_sha)
182+
old_commit = old_sha
180183
# END message handling
181184

182185
return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary)

0 commit comments

Comments
 (0)