From bccdb483aaa7235b85a49f2c208ee1befd2706dd Mon Sep 17 00:00:00 2001 From: Benedikt Morbach Date: Tue, 21 Apr 2015 13:28:13 +0200 Subject: [PATCH 1/2] test: Make git-daemon only listen on localhost No reason to expose a daemon to all interfaces when it is only used for tests, which connect to localhost anyway. I'd love to use localhost here instead, but the git-daemon man page points out: If IPv6 is not supported, then --listen=hostname is also not supported and --listen must be given an IPv4 address. I don't know of a way to check if git has ipv6 support, but 127.0.0.1 should be around for the foreseeable future --- git/test/lib/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 541b972de..77ab82ff0 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -200,7 +200,7 @@ def remote_repo_creator(self): temp_dir = osp(_mktemp()) # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it try: - gd = Git().daemon(temp_dir, enable='receive-pack', as_process=True) + gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', 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: From c1cedc5c417ddf3c2a955514dcca6fe74913259b Mon Sep 17 00:00:00 2001 From: Benedikt Morbach Date: Tue, 21 Apr 2015 13:45:02 +0200 Subject: [PATCH 2/2] test: make git-daemon port configurable via env add a GIT_PYTHON_TEST_GIT_DAEMON_PORT to set a port other than 9418, for example for when you already have a daemon running on that port. --- git/test/lib/helper.py | 10 +++++++--- git/test/test_remote.py | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 77ab82ff0..8be2881c3 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -18,10 +18,11 @@ osp = os.path.dirname GIT_REPO = os.environ.get("GIT_PYTHON_TEST_GIT_REPO_BASE", osp(osp(osp(osp(__file__))))) +GIT_DAEMON_PORT = os.environ.get("GIT_PYTHON_TEST_GIT_DAEMON_PORT", "9418") __all__ = ( 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter', - 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO' + 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO', 'GIT_DAEMON_PORT' ) #{ Routines @@ -193,14 +194,15 @@ def remote_repo_creator(self): # by the user, not by us d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir) d_remote.fetch() - remote_repo_url = "git://localhost%s" % remote_repo_dir + remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir) 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 try: - gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', as_process=True) + 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: @@ -223,6 +225,8 @@ def remote_repo_creator(self): 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=' + msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to ' msg %= temp_dir raise AssertionError(msg) # END make assertion diff --git a/git/test/test_remote.py b/git/test/test_remote.py index c419ecee9..af854988f 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -8,7 +8,8 @@ TestBase, with_rw_repo, with_rw_and_rw_remote_repo, - fixture + fixture, + GIT_DAEMON_PORT ) from git import ( RemoteProgress, @@ -250,7 +251,7 @@ def get_info(res, remote, name): # must clone with a local path for the repo implementation not to freak out # as it wants local paths only ( which I can understand ) other_repo = remote_repo.clone(other_repo_dir, shared=False) - remote_repo_url = "git://localhost%s" % remote_repo.git_dir + remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo.git_dir) # put origin to git-url other_origin = other_repo.remotes.origin