Skip to content

Commit

Permalink
update tests and add a comment about different behaviour of 'push' vs…
Browse files Browse the repository at this point in the history
… 'fetch'
  • Loading branch information
sroet authored and Byron committed Sep 18, 2021
1 parent ef0ca65 commit 0a58afe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions git/remote.py
Expand Up @@ -795,6 +795,8 @@ def stdout_handler(line: str) -> None:
try:
proc.wait(stderr=stderr_text)
except Exception:
# 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:
Expand Down
20 changes: 17 additions & 3 deletions test/test_remote.py
Expand Up @@ -6,6 +6,7 @@

import random
import tempfile
import pytest
from unittest import skipIf

from git import (
Expand Down Expand Up @@ -401,12 +402,12 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
res = remote.push(all=True)
self._do_test_push_result(res, remote)

remote.pull('master', timeout=10.0)
remote.pull('master', kill_after_timeout=10.0)

# cleanup - delete created tags and branches as we are in an innerloop on
# the same repository
TagReference.delete(rw_repo, new_tag, other_tag)
remote.push(":%s" % other_tag.path, timeout=10.0)
remote.push(":%s" % other_tag.path, kill_after_timeout=10.0)

@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes!")
@with_rw_and_rw_remote_repo('0.1.6')
Expand Down Expand Up @@ -467,7 +468,8 @@ def test_base(self, rw_repo, remote_repo):
# Only for remotes - local cases are the same or less complicated
# as additional progress information will never be emitted
if remote.name == "daemon_origin":
self._do_test_fetch(remote, rw_repo, remote_repo, timeout=10.0)
self._do_test_fetch(remote, rw_repo, remote_repo,
kill_after_timeout=10.0)
ran_fetch_test = True
# END fetch test

Expand Down Expand Up @@ -651,3 +653,15 @@ def test_push_error(self, repo):
rem = repo.remote('origin')
with self.assertRaisesRegex(GitCommandError, "src refspec __BAD_REF__ does not match any"):
rem.push('__BAD_REF__')


class TestTimeouts(TestBase):
@with_rw_repo('HEAD', bare=False)
def test_timeout_funcs(self, repo):
for function in ["pull", "fetch"]: #"can't get push to reliably timeout
f = getattr(repo.remotes.origin, function)
assert f is not None # Make sure these functions exist

with self.assertRaisesRegex(GitCommandError,
"kill_after_timeout=0.01 s"):
f(kill_after_timeout=0.01)

0 comments on commit 0a58afe

Please sign in to comment.