5
5
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
6
from __future__ import print_function
7
7
8
- import os
9
- from unittest import TestCase
10
- import time
11
- import tempfile
8
+ from functools import wraps
12
9
import io
13
10
import logging
11
+ import os
12
+ import tempfile
13
+ import textwrap
14
+ import time
15
+ from unittest import TestCase
14
16
15
- from functools import wraps
16
-
17
- from git .util import rmtree
18
17
from git .compat import string_types , is_win
19
- import textwrap
18
+ from git .util import rmtree
19
+
20
+ import os .path as osp
20
21
21
- osp = os .path .dirname
22
22
23
- GIT_REPO = os .environ .get ("GIT_PYTHON_TEST_GIT_REPO_BASE" , osp (osp (osp (osp (__file__ )))))
23
+ ospd = osp .dirname
24
+
25
+ GIT_REPO = os .environ .get ("GIT_PYTHON_TEST_GIT_REPO_BASE" , ospd (ospd (ospd (ospd (__file__ )))))
24
26
GIT_DAEMON_PORT = os .environ .get ("GIT_PYTHON_TEST_GIT_DAEMON_PORT" , "9418" )
25
27
26
28
__all__ = (
40
42
41
43
42
44
def fixture_path (name ):
43
- test_dir = osp ( osp (__file__ ))
44
- return os . path .join (test_dir , "fixtures" , name )
45
+ test_dir = ospd ( ospd (__file__ ))
46
+ return osp .join (test_dir , "fixtures" , name )
45
47
46
48
47
49
def fixture (name ):
@@ -50,7 +52,7 @@ def fixture(name):
50
52
51
53
52
54
def absolute_project_path ():
53
- return os . path . abspath (os . path .join (osp (__file__ ), ".." , ".." ))
55
+ return osp . abspath (osp .join (osp (__file__ ), ".." , ".." ))
54
56
55
57
#} END routines
56
58
@@ -170,26 +172,31 @@ def repo_creator(self):
170
172
return argument_passer
171
173
172
174
173
- def launch_git_daemon (temp_dir , ip , port ):
175
+ def launch_git_daemon (base_path , ip , port ):
174
176
from git import Git
175
177
if is_win :
176
178
## On MINGW-git, daemon exists in .\Git\mingw64\libexec\git-core\,
177
179
# but if invoked as 'git daemon', it detaches from parent `git` cmd,
178
180
# and then CANNOT DIE!
179
181
# So, invoke it as a single command.
180
- ## Cygwin-git has no daemon.
182
+ ## Cygwin-git has no daemon. But it can use MINGW's.
181
183
#
182
- daemon_cmd = ['git-daemon' , temp_dir ,
184
+ daemon_cmd = ['git-daemon' ,
183
185
'--enable=receive-pack' ,
184
186
'--listen=%s' % ip ,
185
- '--port=%s' % port ]
187
+ '--port=%s' % port ,
188
+ '--base-path=%s' % base_path ,
189
+ base_path ]
186
190
gd = Git ().execute (daemon_cmd , as_process = True )
187
191
else :
188
- gd = Git ().daemon (temp_dir ,
192
+ gd = Git ().daemon (base_path ,
189
193
enable = 'receive-pack' ,
190
194
listen = ip ,
191
195
port = port ,
196
+ base_path = base_path ,
192
197
as_process = True )
198
+ # yes, I know ... fortunately, this is always going to work if sleep time is just large enough
199
+ time .sleep (0.5 )
193
200
return gd
194
201
195
202
@@ -217,7 +224,8 @@ def case(self, rw_repo, rw_remote_repo)
217
224
See working dir info in with_rw_repo
218
225
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
219
226
"""
220
- from git import Remote , GitCommandError
227
+ from git import Git , Remote , GitCommandError
228
+
221
229
assert isinstance (working_tree_ref , string_types ), "Decorator requires ref name for working tree checkout"
222
230
223
231
def argument_passer (func ):
@@ -245,23 +253,36 @@ def remote_repo_creator(self):
245
253
pass
246
254
crw .set (section , "receivepack" , True )
247
255
248
- # initialize the remote - first do it as local remote and pull, then
249
- # we change the url to point to the daemon. The daemon should be started
250
- # by the user, not by us
256
+ # Initialize the remote - first do it as local remote and pull, then
257
+ # we change the url to point to the daemon.
251
258
d_remote = Remote .create (rw_repo , "daemon_origin" , remote_repo_dir )
252
259
d_remote .fetch ()
253
- remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT , remote_repo_dir )
254
260
261
+ base_path , rel_repo_dir = osp .split (remote_repo_dir )
262
+
263
+ remote_repo_url = "git://localhost:%s/%s" % (GIT_DAEMON_PORT , rel_repo_dir )
255
264
with d_remote .config_writer as cw :
256
265
cw .set ('url' , remote_repo_url )
257
266
258
- temp_dir = osp (_mktemp ())
259
- gd = launch_git_daemon (temp_dir , '127.0.0.1' , GIT_DAEMON_PORT )
260
267
try :
261
- # yes, I know ... fortunately, this is always going to work if sleep time is just large enough
262
- time .sleep (0.5 )
263
- # end
264
-
268
+ gd = launch_git_daemon (Git .polish_url (base_path ), '127.0.0.1' , GIT_DAEMON_PORT )
269
+ except Exception as ex :
270
+ if is_win :
271
+ msg = textwrap .dedent ("""
272
+ The `git-daemon.exe` must be in PATH.
273
+ For MINGW, look into .\Git\mingw64\libexec\git-core\), but problems with paths might appear.
274
+ CYGWIN has no daemon, but if one exists, it gets along fine (has also paths problems)
275
+ Anyhow, alternatively try starting `git-daemon` manually:""" )
276
+ else :
277
+ msg = "Please try starting `git-daemon` manually:"
278
+ msg += textwrap .dedent ("""
279
+ git daemon --enable=receive-pack --base-path=%s %s
280
+ You can also run the daemon on a different port by passing --port=<port>"
281
+ and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
282
+ """ % (base_path , base_path ))
283
+ raise AssertionError (ex , msg )
284
+ # END make assertion
285
+ else :
265
286
# try to list remotes to diagnoes whether the server is up
266
287
try :
267
288
rw_repo .git .ls_remote (d_remote )
@@ -283,15 +304,6 @@ def remote_repo_creator(self):
283
304
Anyhow, alternatively try starting `git-daemon` manually:""" )
284
305
else :
285
306
msg = "Please try starting `git-daemon` manually:"
286
-
287
- msg += textwrap .dedent ("""
288
- git daemon --enable=receive-pack '%s'
289
- You can also run the daemon on a different port by passing --port=<port>"
290
- and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
291
- """ % temp_dir )
292
- from nose import SkipTest
293
- raise SkipTest (msg ) if is_win else AssertionError (msg )
294
- # END make assertion
295
307
# END catch ls remote error
296
308
297
309
# adjust working dir
@@ -359,7 +371,7 @@ class TestBase(TestCase):
359
371
360
372
def _small_repo_url (self ):
361
373
""":return" a path to a small, clonable repository"""
362
- return os . path .join (self .rorepo .working_tree_dir , 'git/ext/gitdb/gitdb/ext/smmap' )
374
+ return osp .join (self .rorepo .working_tree_dir , 'git/ext/gitdb/gitdb/ext/smmap' )
363
375
364
376
@classmethod
365
377
def setUpClass (cls ):
@@ -383,7 +395,7 @@ def _make_file(self, rela_path, data, repo=None):
383
395
with the given data. Returns absolute path to created file.
384
396
"""
385
397
repo = repo or self .rorepo
386
- abs_path = os . path .join (repo .working_tree_dir , rela_path )
398
+ abs_path = osp .join (repo .working_tree_dir , rela_path )
387
399
with open (abs_path , "w" ) as fp :
388
400
fp .write (data )
389
401
return abs_path
0 commit comments