Skip to content

Commit 996a6eb

Browse files
codexByron
authored andcommitted
fix(remote): drain push status output before resolving hashes
Resolving revision sources in the stdout reader made optional object lookups count against `kill_after_timeout`. A push could finish on the receiver while the reader was still resolving hashes, report a timeout, and lose statuses later in the stream. Collect the raw porcelain lines during the timed drain and parse the captured lines once the drain returns. A subprocess regression checks that disambiguation happens after stdout closes and that both statuses are retained. The partial-timeout test still passes on both backends. Agent-Model: unknown
1 parent eb37351 commit 996a6eb

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎git/remote.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,22 +913,23 @@ def _get_push_info(
913913
# to override the previous one. This is why we read the bytes manually.
914914
progress_handler = progress.new_message_handler()
915915
output: PushInfoList = PushInfoList()
916-
917-
def stdout_handler(line: str) -> None:
918-
try:
919-
output.append(PushInfo._from_line(self, line))
920-
except ValueError:
921-
# If an error happens, additional info is given which we parse below.
922-
pass
916+
push_info_lines: List[str] = []
923917

924918
handle_process_output(
925919
proc,
926-
stdout_handler,
920+
push_info_lines.append,
927921
progress_handler,
928922
finalizer=None,
929923
decode_streams=False,
930924
kill_after_timeout=kill_after_timeout,
931925
)
926+
# Optional lookups are independent of the push's process timeout.
927+
for line in list(push_info_lines):
928+
try:
929+
output.append(PushInfo._from_line(self, line))
930+
except ValueError:
931+
# Non-status lines are handled through stderr and the exit code below.
932+
pass
932933
stderr_text = "\n".join(progress.error_lines)
933934
try:
934935
proc.wait(stderr=stderr_text)

‎test/test_remote.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,34 @@ def stall():
11961196

11971197

11981198
class TestTimeouts(TestBase):
1199+
@skipIf(sys.platform == "win32", "requires POSIX timeout signalling")
1200+
@with_rw_repo("HEAD", bare=False)
1201+
def test_push_hash_lookup_waits_for_status_output(self, repo):
1202+
current = repo.head.commit
1203+
parent = current.parents[0]
1204+
lines = (
1205+
f"+\tHEAD~1:refs/heads/snapshot\t{current.hexsha[:12]}...{parent.hexsha[:12]} (forced update)\n"
1206+
"=\tHEAD:refs/heads/ordinary\t[up to date]"
1207+
)
1208+
process = repo.git.execute(
1209+
[sys.executable, "-c", f"print({lines!r})"], as_process=True, universal_newlines=True
1210+
)
1211+
run = Git._call_process_safe
1212+
stream_closed = []
1213+
1214+
def track_disambiguate(git, method, *args, **kwargs):
1215+
if method == "rev_parse" and args[0].startswith("--disambiguate="):
1216+
stream_closed.append(process.stdout.closed)
1217+
return run(git, method, *args, **kwargs)
1218+
1219+
with mock.patch.object(Git, "_call_process_safe", track_disambiguate):
1220+
result = repo.remote("origin")._get_push_info(process, None, kill_after_timeout=5)
1221+
1222+
result.raise_if_error()
1223+
assert stream_closed == [True]
1224+
assert [info.remote_ref_string for info in result] == ["refs/heads/snapshot", "refs/heads/ordinary"]
1225+
assert result[0].local_hash == parent.hexsha
1226+
11991227
@skipIf(sys.platform == "win32", "requires POSIX timeout signalling")
12001228
@with_rw_repo("HEAD", bare=False)
12011229
def test_timeout_partial_push(self, repo):

0 commit comments

Comments
 (0)