Skip to content

Commit f7ca1ce

Browse files
committed
Submodule tests are nearly working. Only root module needs more attention
1 parent 93668b0 commit f7ca1ce

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

git/objects/submodule/base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030

3131
import stat
32-
import git
32+
import git # we use some types indirectly to prevent cyclic imports !
3333

3434
import os
3535
import sys
@@ -769,14 +769,18 @@ def config_writer(self, index=None, write=True):
769769
#{ Query Interface
770770

771771
@unbare_repo
772-
def module(self):
773-
""":return: Repo instance initialized from the repository at our submodule path
772+
def module(self, repoType=None):
773+
""":return: Repository instance initialized from the repository at our submodule path
774+
:param repoType: The type of repository to be created. It must be possible to instatiate it
775+
from a single repository path.
776+
If None, a default repository type will be used
774777
:raise InvalidGitRepositoryError: if a repository was not available. This could
775778
also mean that it was not yet initialized"""
776779
# late import to workaround circular dependencies
777-
module_path = self.abspath
780+
module_path = self.abspath
781+
repoType = repoType or git.Repo
778782
try:
779-
repo = git.Repo(module_path)
783+
repo = repoType(module_path)
780784
if repo != self.repo:
781785
return repo
782786
# END handle repo uninitialized

git/test/objects/test_submodule.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shutil
1111
import git
1212
import os
13+
import sys
1314

1415
class TestRootProgress(RootUpdateProgress):
1516
"""Just prints messages, for now without checking the correctness of the states"""
@@ -25,6 +26,10 @@ class TestSubmodule(TestObjectBase):
2526
k_subm_changed = "394ed7006ee5dc8bddfd132b64001d5dfc0ffdd3"
2627
k_no_subm_tag = "0.1.6"
2728

29+
env_gitdb_local_path = "GITPYTHON_TEST_GITDB_LOCAL_PATH"
30+
31+
def _generate_async_local_path(self):
32+
return to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, 'git/ext/async'))
2833

2934
def _do_base_tests(self, rwrepo):
3035
"""Perform all tests in the given repository, it may be bare or nonbare"""
@@ -41,9 +46,9 @@ def _do_base_tests(self, rwrepo):
4146
# at a different time, there is None
4247
assert len(Submodule.list_items(rwrepo, self.k_no_subm_tag)) == 0
4348

44-
assert sm.path == 'git/ext/git'
49+
assert sm.path == 'git/ext/gitdb'
4550
assert sm.path != sm.name # in our case, we have ids there, which don't equal the path
46-
assert sm.url == 'git://github.com/gitpython-developers/git.git'
51+
assert sm.url == 'git://github.com/gitpython-developers/gitdb.git'
4752
assert sm.branch_path == 'refs/heads/master' # the default ...
4853
assert sm.branch_name == 'master'
4954
assert sm.parent_commit == rwrepo.head.commit
@@ -74,13 +79,21 @@ def _do_base_tests(self, rwrepo):
7479
if rwrepo.bare:
7580
self.failUnlessRaises(InvalidGitRepositoryError, sm.config_writer)
7681
else:
77-
writer = sm.config_writer()
7882
# for faster checkout, set the url to the local path
79-
new_smclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path))
80-
writer.set_value('url', new_smclone_path)
81-
del(writer)
82-
assert sm.config_reader().get_value('url') == new_smclone_path
83-
assert sm.url == new_smclone_path
83+
# Note: This is nice but doesn't work anymore with the latest git-python
84+
# version. This would also mean we need internet for this to work which
85+
# 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+
8497
# END handle bare repo
8598
smold.config_reader()
8699

@@ -176,7 +189,8 @@ def _do_base_tests(self, rwrepo):
176189
csm_repopath = csm.path
177190

178191
# adjust the path of the submodules module to point to the local destination
179-
new_csmclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path, csm.path))
192+
# In the current gitpython version, async is used directly by gitpython
193+
new_csmclone_path = self._generate_async_local_path()
180194
csm.config_writer().set_value('url', new_csmclone_path)
181195
assert csm.url == new_csmclone_path
182196

@@ -248,6 +262,10 @@ def _do_base_tests(self, rwrepo):
248262
self.failUnlessRaises(InvalidGitRepositoryError, sm.remove, dry_run=True)
249263
sm.module().index.reset(working_tree=True)
250264

265+
# make sure sub-submodule is not modified by forcing it to update
266+
# to the revision it is supposed to point to.
267+
csm.update()
268+
251269
# this would work
252270
assert sm.remove(dry_run=True) is sm
253271
assert sm.module_exists()

0 commit comments

Comments
 (0)