@@ -25,12 +25,28 @@ class TestSubmodule(TestObjectBase):
25
25
k_subm_current = "468cad66ff1f80ddaeee4123c24e4d53a032c00d"
26
26
k_subm_changed = "394ed7006ee5dc8bddfd132b64001d5dfc0ffdd3"
27
27
k_no_subm_tag = "0.1.6"
28
-
28
+ k_github_gitdb_url = 'git://github.com/gitpython-developers/gitdb.git'
29
29
env_gitdb_local_path = "GITPYTHON_TEST_GITDB_LOCAL_PATH"
30
30
31
31
def _generate_async_local_path (self ):
32
32
return to_native_path_linux (join_path_native (self .rorepo .working_tree_dir , 'git/ext/async' ))
33
33
34
+ def _rewrite_gitdb_to_local_path (self , smgitdb ):
35
+ """Rewrites the given submodule to point to the local path of the gitdb repository, if possible.
36
+ Otherwise it leaves it unchanged
37
+ :return: new clone path, or None if no new path was set"""
38
+ new_smclone_path = os .environ .get (self .env_gitdb_local_path )
39
+ if new_smclone_path is not None :
40
+ writer = smgitdb .config_writer ()
41
+ writer .set_value ('url' , new_smclone_path )
42
+ del (writer )
43
+ assert smgitdb .config_reader ().get_value ('url' ) == new_smclone_path
44
+ assert smgitdb .url == new_smclone_path
45
+ else :
46
+ sys .stderr .write ("Submodule tests need the gitdb repository. You can specify a local source setting the %s environment variable. Otherwise it will be downloaded from the internet" % self .env_gitdb_local_path )
47
+ #END handle submodule path
48
+ return new_smclone_path
49
+
34
50
def _do_base_tests (self , rwrepo ):
35
51
"""Perform all tests in the given repository, it may be bare or nonbare"""
36
52
# manual instantiation
@@ -48,7 +64,7 @@ def _do_base_tests(self, rwrepo):
48
64
49
65
assert sm .path == 'git/ext/gitdb'
50
66
assert sm .path != sm .name # in our case, we have ids there, which don't equal the path
51
- assert sm .url == 'git://github.com/gitpython-developers/gitdb.git'
67
+ assert sm .url == self . k_github_gitdb_url
52
68
assert sm .branch_path == 'refs/heads/master' # the default ...
53
69
assert sm .branch_name == 'master'
54
70
assert sm .parent_commit == rwrepo .head .commit
@@ -83,17 +99,7 @@ def _do_base_tests(self, rwrepo):
83
99
# Note: This is nice but doesn't work anymore with the latest git-python
84
100
# version. This would also mean we need internet for this to work which
85
101
# is why we allow an override using an environment variable
86
- new_smclone_path = os .environ .get (self .env_gitdb_local_path )
87
- if new_smclone_path is not None :
88
- writer = sm .config_writer ()
89
- writer .set_value ('url' , new_smclone_path )
90
- del (writer )
91
- assert sm .config_reader ().get_value ('url' ) == new_smclone_path
92
- assert sm .url == new_smclone_path
93
- else :
94
- sys .stderr .write ("Submodule tests need the gitdb repository. You can specify a local source setting the %s environment variable. Otherwise it will be downloaded from the internet" % self .env_gitdb_local_path )
95
- #END handle submodule path
96
-
102
+ new_smclone_path = self ._rewrite_gitdb_to_local_path (sm )
97
103
# END handle bare repo
98
104
smold .config_reader ()
99
105
@@ -405,7 +411,7 @@ def test_root_module(self, rwrepo):
405
411
406
412
# deep traversal git / async
407
413
rsmsp = [sm .path for sm in rm .traverse ()]
408
- assert len (rsmsp ) == 2 # git and async, async being a child of git
414
+ assert len (rsmsp ) == 1 # git and async, async being a child of git
409
415
410
416
# cannot set the parent commit as root module's path didn't exist
411
417
self .failUnlessRaises (ValueError , rm .set_parent_commit , 'HEAD' )
@@ -425,8 +431,8 @@ def test_root_module(self, rwrepo):
425
431
prep = sm .path
426
432
assert not sm .module_exists () # was never updated after rwrepo's clone
427
433
428
- # assure we clone from a local source
429
- sm . config_writer (). set_value ( 'url' , to_native_path_linux ( join_path_native ( self .rorepo . working_tree_dir , sm . path )) )
434
+ # assure we clone from a local source
435
+ self ._rewrite_gitdb_to_local_path ( sm )
430
436
431
437
# dry-run does nothing
432
438
sm .update (recursive = False , dry_run = True , progress = prog )
@@ -459,7 +465,7 @@ def test_root_module(self, rwrepo):
459
465
#================
460
466
nsmn = "newsubmodule"
461
467
nsmp = "submrepo"
462
- async_url = to_native_path_linux ( join_path_native ( self .rorepo . working_tree_dir , rsmsp [ 0 ], rsmsp [ 1 ]) )
468
+ async_url = self ._generate_async_local_path ( )
463
469
nsm = Submodule .add (rwrepo , nsmn , nsmp , url = async_url )
464
470
csmadded = rwrepo .index .commit ("Added submodule" ).hexsha # make sure we don't keep the repo reference
465
471
nsm .set_parent_commit (csmadded )
@@ -501,7 +507,11 @@ def test_root_module(self, rwrepo):
501
507
# to the first repository, this way we have a fast checkout, and a completely different
502
508
# repository at the different url
503
509
nsm .set_parent_commit (csmremoved )
504
- nsmurl = to_native_path_linux (join_path_native (self .rorepo .working_tree_dir , rsmsp [0 ]))
510
+ nsmurl = os .environ .get (self .env_gitdb_local_path , self .k_github_gitdb_url )
511
+
512
+ # Note: We would have liked to have a different url, but we cannot
513
+ # provoke this case
514
+ assert nsm .url != nsmurl
505
515
nsm .config_writer ().set_value ('url' , nsmurl )
506
516
csmpathchange = rwrepo .index .commit ("changed url" )
507
517
nsm .set_parent_commit (csmpathchange )
0 commit comments