|
14 | 14 |
|
15 | 15 | from git import Repo, Remote, GitCommandError, Git |
16 | 16 | from git.compat import string_types, is_win |
| 17 | +import textwrap |
17 | 18 |
|
18 | 19 | osp = os.path.dirname |
19 | 20 |
|
@@ -201,55 +202,61 @@ def remote_repo_creator(self): |
201 | 202 | d_remote.config_writer.set('url', remote_repo_url) |
202 | 203 |
|
203 | 204 | temp_dir = osp(_mktemp()) |
204 | | - # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it |
| 205 | + # On MINGW-git, daemon exists, in Cygwin-git, this will fail. |
| 206 | + gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT, |
| 207 | + as_process=True) |
205 | 208 | try: |
206 | | - gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT, |
207 | | - as_process=True) |
208 | 209 | # yes, I know ... fortunately, this is always going to work if sleep time is just large enough |
209 | 210 | time.sleep(0.5) |
210 | | - except Exception: |
211 | | - gd = None |
212 | 211 | # end |
213 | 212 |
|
214 | | - # try to list remotes to diagnoes whether the server is up |
215 | | - try: |
216 | | - rw_repo.git.ls_remote(d_remote) |
217 | | - except GitCommandError as e: |
218 | | - # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway |
219 | | - # Of course we expect it to work here already, but maybe there are timing constraints |
220 | | - # on some platforms ? |
221 | | - if gd is not None: |
222 | | - gd.proc.terminate() |
223 | | - log.warning('git-ls-remote failed due to: %s(%s)', type(e), e) |
224 | | - if is_win(): |
225 | | - msg = "git-daemon needs to run this test, but windows does not have one. " |
226 | | - msg += 'Otherwise, run: git-daemon "%s"' % temp_dir |
227 | | - raise AssertionError(msg) |
228 | | - else: |
229 | | - msg = 'Please start a git-daemon to run this test, execute: git daemon --enable=receive-pack "%s"' |
230 | | - msg += 'You can also run the daemon on a different port by passing --port=<port>' |
231 | | - msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>' |
232 | | - msg %= temp_dir |
| 213 | + # try to list remotes to diagnoes whether the server is up |
| 214 | + try: |
| 215 | + rw_repo.git.ls_remote(d_remote) |
| 216 | + except GitCommandError as e: |
| 217 | + # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway |
| 218 | + # Of course we expect it to work here already, but maybe there are timing constraints |
| 219 | + # on some platforms ? |
| 220 | + if gd is not None: |
| 221 | + gd.proc.terminate() |
| 222 | + log.warning('git(%s) ls-remote failed due to:%s', |
| 223 | + rw_repo.git_dir, e) |
| 224 | + if is_win(): |
| 225 | + msg = textwrap.dedent(""" |
| 226 | + MINGW yet has problems with paths, CYGWIN additionally is missing `git-daemon` |
| 227 | + needed to run this test. Anyhow, try starting `git-daemon` manually:""") |
| 228 | + else: |
| 229 | + msg = "Please try starting `git-daemon` manually:" |
| 230 | + |
| 231 | + msg += textwrap.dedent(""" |
| 232 | + git daemon --enable=receive-pack '%s' |
| 233 | + You can also run the daemon on a different port by passing --port=<port>" |
| 234 | + and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port> |
| 235 | + """ % temp_dir) |
233 | 236 | raise AssertionError(msg) |
234 | | - # END make assertion |
235 | | - # END catch ls remote error |
| 237 | + # END make assertion |
| 238 | + # END catch ls remote error |
| 239 | + |
| 240 | + # adjust working dir |
| 241 | + prev_cwd = os.getcwd() |
| 242 | + os.chdir(rw_repo.working_dir) |
236 | 243 |
|
237 | | - # adjust working dir |
238 | | - prev_cwd = os.getcwd() |
239 | | - os.chdir(rw_repo.working_dir) |
240 | | - try: |
241 | 244 | try: |
242 | 245 | return func(self, rw_repo, rw_remote_repo) |
243 | 246 | except: |
244 | 247 | log.info("Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s", |
245 | 248 | repo_dir, remote_repo_dir) |
246 | 249 | repo_dir = remote_repo_dir = None |
247 | 250 | raise |
| 251 | + finally: |
| 252 | + os.chdir(prev_cwd) |
| 253 | + |
248 | 254 | finally: |
249 | 255 | if gd is not None: |
250 | 256 | gd.proc.terminate() |
251 | 257 |
|
252 | | - os.chdir(prev_cwd) |
| 258 | + import gc |
| 259 | + gc.collect() |
253 | 260 | rw_repo.git.clear_cache() |
254 | 261 | rw_remote_repo.git.clear_cache() |
255 | 262 | if repo_dir: |
|
0 commit comments