summaryrefslogtreecommitdiff
path: root/git/test/lib/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/test/lib/helper.py')
-rw-r--r--git/test/lib/helper.py69
1 files changed, 38 insertions, 31 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 7cc1dcae..9e6be3e3 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -14,6 +14,7 @@ import logging
from git import Repo, Remote, GitCommandError, Git
from git.compat import string_types, is_win
+import textwrap
osp = os.path.dirname
@@ -201,43 +202,45 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
d_remote.config_writer.set('url', remote_repo_url)
temp_dir = osp(_mktemp())
- # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it
+ # On MINGW-git, daemon exists, in Cygwin-git, this will fail.
+ gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT,
+ as_process=True)
try:
- gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT,
- as_process=True)
# yes, I know ... fortunately, this is always going to work if sleep time is just large enough
time.sleep(0.5)
- except Exception:
- gd = None
# end
- # try to list remotes to diagnoes whether the server is up
- try:
- rw_repo.git.ls_remote(d_remote)
- except GitCommandError as e:
- # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
- # Of course we expect it to work here already, but maybe there are timing constraints
- # on some platforms ?
- if gd is not None:
- gd.proc.terminate()
- log.warning('git-ls-remote failed due to: %s(%s)', type(e), e)
- if is_win():
- msg = "git-daemon needs to run this test, but windows does not have one. "
- msg += 'Otherwise, run: git-daemon "%s"' % temp_dir
- raise AssertionError(msg)
- else:
- msg = 'Please start a git-daemon to run this test, execute: git daemon --enable=receive-pack "%s"'
- msg += 'You can also run the daemon on a different port by passing --port=<port>'
- msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>'
- msg %= temp_dir
+ # try to list remotes to diagnoes whether the server is up
+ try:
+ rw_repo.git.ls_remote(d_remote)
+ except GitCommandError as e:
+ # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
+ # Of course we expect it to work here already, but maybe there are timing constraints
+ # on some platforms ?
+ if gd is not None:
+ gd.proc.terminate()
+ log.warning('git(%s) ls-remote failed due to:%s',
+ rw_repo.git_dir, e)
+ if is_win():
+ msg = textwrap.dedent("""
+ MINGW yet has problems with paths, CYGWIN additionally is missing `git-daemon`
+ needed to run this test. Anyhow, try starting `git-daemon` manually:""")
+ else:
+ msg = "Please try starting `git-daemon` manually:"
+
+ msg += textwrap.dedent("""
+ git daemon --enable=receive-pack '%s'
+ You can also run the daemon on a different port by passing --port=<port>"
+ and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
+ """ % temp_dir)
raise AssertionError(msg)
- # END make assertion
- # END catch ls remote error
+ # END make assertion
+ # END catch ls remote error
+
+ # adjust working dir
+ prev_cwd = os.getcwd()
+ os.chdir(rw_repo.working_dir)
- # adjust working dir
- prev_cwd = os.getcwd()
- os.chdir(rw_repo.working_dir)
- try:
try:
return func(self, rw_repo, rw_remote_repo)
except:
@@ -245,11 +248,15 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
repo_dir, remote_repo_dir)
repo_dir = remote_repo_dir = None
raise
+ finally:
+ os.chdir(prev_cwd)
+
finally:
if gd is not None:
gd.proc.terminate()
- os.chdir(prev_cwd)
+ import gc
+ gc.collect()
rw_repo.git.clear_cache()
rw_remote_repo.git.clear_cache()
if repo_dir: