Skip to content

Commit 6e56b3c

Browse files
committed
daemon, gitpython-developers#525: simplify exception handling
1 parent d78433b commit 6e56b3c

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

git/test/lib/helper.py

+5-33
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from unittest import TestCase
1616

1717
from git.compat import string_types, is_win
18-
from git.util import rmtree, HIDE_WINDOWS_KNOWN_ERRORS
18+
from git.util import rmtree
1919

2020
import os.path as osp
2121

@@ -214,7 +214,7 @@ def case(self, rw_repo, rw_remote_repo)
214214
See working dir info in with_rw_repo
215215
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
216216
"""
217-
from git import Git, Remote, GitCommandError
217+
from git import Git, Remote
218218

219219
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
220220

@@ -273,37 +273,8 @@ def remote_repo_creator(self):
273273
raise AssertionError(ex, msg)
274274
# END make assertion
275275
else:
276-
# try to list remotes to diagnoes whether the server is up
277-
try:
278-
rw_repo.git.ls_remote(d_remote)
279-
except GitCommandError as e:
280-
# We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
281-
# Of course we expect it to work here already, but maybe there are timing constraints
282-
# on some platforms ?
283-
try:
284-
gd.proc.terminate()
285-
except Exception as ex:
286-
log.debug("Ignoring %r while terminating proc after %r.", ex, e)
287-
log.warning('git(%s) ls-remote failed due to:%s',
288-
rw_repo.git_dir, e)
289-
if is_win:
290-
msg = textwrap.dedent("""
291-
MINGW yet has problems with paths, and `git-daemon.exe` must be in PATH
292-
(look into .\Git\mingw64\libexec\git-core\);
293-
CYGWIN has no daemon, but if one exists, it gets along fine (has also paths problems)
294-
Anyhow, alternatively try starting `git-daemon` manually:""")
295-
else:
296-
msg = "Please try starting `git-daemon` manually:"
297-
298-
msg += textwrap.dedent("""
299-
git daemon --enable=receive-pack '%s'
300-
You can also run the daemon on a different port by passing --port=<port>"
301-
and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
302-
""" % base_path)
303-
from unittest import SkipTest
304-
raise SkipTest(msg) if HIDE_WINDOWS_KNOWN_ERRORS else AssertionError(e, msg)
305-
# END make assertion
306-
# END catch ls remote error
276+
# Try listing remotes, to diagnose whether the daemon is up.
277+
rw_repo.git.ls_remote(d_remote)
307278

308279
# adjust working dir
309280
prev_cwd = os.getcwd()
@@ -321,6 +292,7 @@ def remote_repo_creator(self):
321292

322293
finally:
323294
try:
295+
log.debug("Killing git-daemon...")
324296
gd.proc.kill()
325297
except:
326298
## Either it has died (and we're here), or it won't die, again here...

0 commit comments

Comments
 (0)