Skip to content
Merged
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
15 changes: 10 additions & 5 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,17 @@ def __init__(self) -> None:
self.error_lines: List[str] = []
self.other_lines: List[str] = []

def _parse_progress_line(self, line: AnyStr) -> None:
def _parse_progress_line(self, line: AnyStr) -> Optional[object]:
"""Parse progress information from the given line as retrieved by
:manpage:`git-push(1)` or :manpage:`git-fetch(1)`.

- Lines that do not contain progress info are stored in :attr:`other_lines`.
- Lines that seem to contain an error (i.e. start with ``error:`` or ``fatal:``)
are stored in :attr:`error_lines`.

The base implementation returns ``None``. Subclasses may return another
value for compatibility with existing overrides, but callers should treat
the return value as unspecified.
"""
# handle
# Counting objects: 4, done.
Expand All @@ -632,7 +636,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:

if self._cur_line.startswith(("error:", "fatal:")):
self.error_lines.append(self._cur_line)
return
return None

cur_count, max_count = None, None
match = self.re_op_relative.match(line_str)
Expand All @@ -642,7 +646,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
if not match:
self.line_dropped(line_str)
self.other_lines.append(line_str)
return
return None
# END could not get match

op_code = 0
Expand Down Expand Up @@ -673,7 +677,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
self.line_dropped(line_str)
# Note: Don't add this line to the other lines, as we have to silently
# drop it.
return
return None
# END handle op code

# Figure out stage.
Expand All @@ -699,6 +703,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
max_count and float(max_count),
message,
)
return None

def new_message_handler(self) -> Callable[[str], None]:
"""
Expand All @@ -708,7 +713,7 @@ def new_message_handler(self) -> Callable[[str], None]:
"""

def handler(line: AnyStr) -> None:
return self._parse_progress_line(line.rstrip())
self._parse_progress_line(line.rstrip())

# END handler

Expand Down
19 changes: 19 additions & 0 deletions test/deprecation/test_remote_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

"""Tests for static characteristics of remote progress helpers."""

from typing import AnyStr

from git import RemoteProgress


def test_parse_progress_line_override_can_return_non_none() -> None:
"""Subclass overrides may return a value without violating base typing."""

class ReturningProgress(RemoteProgress):
def _parse_progress_line(self, line: AnyStr) -> str:
super()._parse_progress_line(line)
return "handled"

assert ReturningProgress()._parse_progress_line("unmatched progress") == "handled"
Loading