diff options
author | Sjoerd Langkemper <sjoerd-github@linuxonly.nl> | 2021-10-12 11:23:39 +0200 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-11-13 15:20:20 +0800 |
commit | 3b82fa3018a21f0eeb76034ecb8fb4dedea9a966 (patch) | |
tree | 33ab5b597fabd4d6385f7c8454061eddf58239f0 /git/remote.py | |
parent | a3efd2458afe535ffd9dcc756d8ba0c931d10ff2 (diff) | |
download | gitpython-3b82fa3018a21f0eeb76034ecb8fb4dedea9a966.tar.gz |
Let remote.push return a PushInfoList
List-like, so that it's backward compatible. But it has a new method
raise_on_error, that throws an exception if anything failed to push.
Related to #621
Diffstat (limited to 'git/remote.py')
-rw-r--r-- | git/remote.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/git/remote.py b/git/remote.py index 2cf5678b..63b4dc51 100644 --- a/git/remote.py +++ b/git/remote.py @@ -116,6 +116,22 @@ def to_progress_instance(progress: Union[Callable[..., Any], RemoteProgress, Non return progress +class PushInfoList(IterableList): + def __new__(cls) -> 'IterableList[IterableObj]': + return super(IterableList, cls).__new__(cls, 'push_infos') + + def __init__(self) -> None: + super().__init__('push_infos') + self.exception = None + + def raise_on_error(self): + """ + Raise an exception if any ref failed to push. + """ + if self.exception: + raise self.exception + + class PushInfo(IterableObj, object): """ Carries information about the result of a push operation of a single head:: @@ -774,7 +790,7 @@ class Remote(LazyMixin, IterableObj): def _get_push_info(self, proc: 'Git.AutoInterrupt', progress: Union[Callable[..., Any], RemoteProgress, None], - kill_after_timeout: Union[None, float] = None) -> IterableList[PushInfo]: + kill_after_timeout: Union[None, float] = None) -> PushInfoList: progress = to_progress_instance(progress) # read progress information from stderr @@ -782,7 +798,7 @@ class Remote(LazyMixin, IterableObj): # read the lines manually as it will use carriage returns between the messages # to override the previous one. This is why we read the bytes manually progress_handler = progress.new_message_handler() - output: IterableList[PushInfo] = IterableList('push_infos') + output: PushInfoList = PushInfoList() def stdout_handler(line: str) -> None: try: @@ -796,13 +812,14 @@ class Remote(LazyMixin, IterableObj): stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or '' try: proc.wait(stderr=stderr_text) - except Exception: + except Exception as e: # This is different than fetch (which fails if there is any std_err # even if there is an output) if not output: raise elif stderr_text: log.warning("Error lines received while fetching: %s", stderr_text) + output.exception = e return output |