| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | import os | |
| 8 | 8 | import sys | |
| 9 | - from git import Repo, Remote, GitCommandError | ||
| 9 | + from git import Repo, Remote, GitCommandError, Git | ||
| 10 | 10 | from unittest import TestCase | |
| 11 | 11 | import tempfile | |
| 12 | 12 | import shutil | |
@@ -149,6 +149,7 @@ def case(self, rw_repo, rw_remote_repo) | |||
| 149 | 149 | This setup allows you to test push and pull scenarios and hooks nicely. | |
| 150 | 150 | ||
| 151 | 151 | See working dir info in with_rw_repo | |
| 152 | + :note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test. | ||
| 152 | 153 | """ | |
| 153 | 154 | assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout" | |
| 154 | 155 | ||
@@ -186,17 +187,30 @@ def remote_repo_creator(self): | |||
| 186 | 187 | ||
| 187 | 188 | d_remote.config_writer.set('url', remote_repo_url) | |
| 188 | 189 | ||
| 190 | + temp_dir = os.path.dirname(_mktemp()) | ||
| 191 | + # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it | ||
| 192 | + try: | ||
| 193 | + gd = Git().daemon(temp_dir, as_process=True) | ||
| 194 | + except Exception as err: | ||
| 195 | + gd = None | ||
| 196 | + # end | ||
| 197 | + | ||
| 189 | 198 | # try to list remotes to diagnoes whether the server is up | |
| 190 | 199 | try: | |
| 191 | 200 | rw_repo.git.ls_remote(d_remote) | |
| 192 | 201 | except GitCommandError, e: | |
| 202 | + # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway | ||
| 203 | + # Of course we expect it to work here already, but maybe there are timing constraints | ||
| 204 | + # on some platforms ? | ||
| 205 | + if gd is not None: | ||
| 206 | + os.kill(gd.proc.pid, 15) | ||
| 193 | 207 | print str(e) | |
| 194 | 208 | if os.name == 'nt': | |
| 195 | 209 | raise AssertionError( | |
| 196 | - 'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"' % os.path.dirname(_mktemp())) | ||
| 210 | + 'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"' % temp_dir) | ||
| 197 | 211 | else: | |
| 198 | 212 | raise AssertionError( | |
| 199 | - 'Please start a git-daemon to run this test, execute: git-daemon "%s"' % os.path.dirname(_mktemp())) | ||
| 213 | + 'Please start a git-daemon to run this test, execute: git-daemon "%s"' % temp_dir) | ||
| 200 | 214 | # END make assertion | |
| 201 | 215 | # END catch ls remote error | |
| 202 | 216 | ||
@@ -206,11 +220,16 @@ def remote_repo_creator(self): | |||
| 206 | 220 | try: | |
| 207 | 221 | return func(self, rw_repo, rw_remote_repo) | |
| 208 | 222 | finally: | |
| 223 | + # gd.proc.kill() ... no idea why that doesn't work | ||
| 224 | + os.kill(gd.proc.pid, 15) | ||
| 225 | + | ||
| 209 | 226 | os.chdir(prev_cwd) | |
| 210 | 227 | rw_repo.git.clear_cache() | |
| 211 | 228 | rw_remote_repo.git.clear_cache() | |
| 212 | 229 | shutil.rmtree(repo_dir, onerror=_rmtree_onerror) | |
| 213 | 230 | shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror) | |
| 231 | + | ||
| 232 | + gd.proc.wait() | ||
| 214 | 233 | # END cleanup | |
| 215 | 234 | # END bare repo creator | |
| 216 | 235 | remote_repo_creator.__name__ = func.__name__ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments