Skip to content

Commit 82793e5

Browse files
committed
Submodule tests are fully back and working
1 parent f7ca1ce commit 82793e5

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

git/test/objects/test_submodule.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,28 @@ class TestSubmodule(TestObjectBase):
2525
k_subm_current = "468cad66ff1f80ddaeee4123c24e4d53a032c00d"
2626
k_subm_changed = "394ed7006ee5dc8bddfd132b64001d5dfc0ffdd3"
2727
k_no_subm_tag = "0.1.6"
28-
28+
k_github_gitdb_url = 'git://github.com/gitpython-developers/gitdb.git'
2929
env_gitdb_local_path = "GITPYTHON_TEST_GITDB_LOCAL_PATH"
3030

3131
def _generate_async_local_path(self):
3232
return to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, 'git/ext/async'))
3333

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+
3450
def _do_base_tests(self, rwrepo):
3551
"""Perform all tests in the given repository, it may be bare or nonbare"""
3652
# manual instantiation
@@ -48,7 +64,7 @@ def _do_base_tests(self, rwrepo):
4864

4965
assert sm.path == 'git/ext/gitdb'
5066
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
5268
assert sm.branch_path == 'refs/heads/master' # the default ...
5369
assert sm.branch_name == 'master'
5470
assert sm.parent_commit == rwrepo.head.commit
@@ -83,17 +99,7 @@ def _do_base_tests(self, rwrepo):
8399
# Note: This is nice but doesn't work anymore with the latest git-python
84100
# version. This would also mean we need internet for this to work which
85101
# 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)
97103
# END handle bare repo
98104
smold.config_reader()
99105

@@ -405,7 +411,7 @@ def test_root_module(self, rwrepo):
405411

406412
# deep traversal git / async
407413
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
409415

410416
# cannot set the parent commit as root module's path didn't exist
411417
self.failUnlessRaises(ValueError, rm.set_parent_commit, 'HEAD')
@@ -425,8 +431,8 @@ def test_root_module(self, rwrepo):
425431
prep = sm.path
426432
assert not sm.module_exists() # was never updated after rwrepo's clone
427433

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)
430436

431437
# dry-run does nothing
432438
sm.update(recursive=False, dry_run=True, progress=prog)
@@ -459,7 +465,7 @@ def test_root_module(self, rwrepo):
459465
#================
460466
nsmn = "newsubmodule"
461467
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()
463469
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=async_url)
464470
csmadded = rwrepo.index.commit("Added submodule").hexsha # make sure we don't keep the repo reference
465471
nsm.set_parent_commit(csmadded)
@@ -501,7 +507,11 @@ def test_root_module(self, rwrepo):
501507
# to the first repository, this way we have a fast checkout, and a completely different
502508
# repository at the different url
503509
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
505515
nsm.config_writer().set_value('url', nsmurl)
506516
csmpathchange = rwrepo.index.commit("changed url")
507517
nsm.set_parent_commit(csmpathchange)

0 commit comments

Comments
 (0)