8000 Basic submodule tests are working once again ! · gitpython-developers/GitPython@d4ce247 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4ce247

Browse files
committed
Basic submodule tests are working once again !
After all, it was easier than expected. It seems that previous assertions the test made should have never been true to begin with. Thus we might have improved the test thanks to our improved implementation. Fixes #233
1 parent c15a6e1 commit d4ce247

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

git/objects/submodule/base.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,23 +458,24 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
458458
# END early abort if init is not allowed
459459

460460
# there is no git-repository yet - but delete empty paths
461-
module_path = self._module_abspath(self.repo, self.path, self.name)
462-
if not dry_run and os.path.isdir(module_path):
461+
checkout_module_abspath = self.abspath
462+
if not dry_run and os.path.isdir(checkout_module_abspath):
463463
try:
464-
os.rmdir(module_path)
464+
os.rmdir(checkout_module_abspath)
465465
except OSError:
466-
raise OSError("Module directory at %r does already exist and is non-empty" % module_path)
466+
raise OSError("Module directory at %r does already exist and is non-empty"
467+
% checkout_module_abspath)
467468
# END handle OSError
468469
# END handle directory removal
469470

470471
# don't check it out at first - nonetheless it will create a local
471472
# branch according to the remote-HEAD if possible
472473
progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning %s to %s in submodule %r" %
473-
(self.url, module_path, self.name))
474+
(self.url, checkout_module_abspath, self.name))
474475
if not dry_run:
475476
mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True)
476477
# END handle dry-run
477-
progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % module_path)
478+
progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath)
478479

479480
if not dry_run:
480481
# see whether we have a valid branch to checkout
@@ -784,6 +785,10 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
784785
# end handle separate bare repository
785786
# END handle module deletion
786787

788+
# void our data not to delay invalid access
789+
if not dry_run:
790+
self._clear_cache()
791+
787792
# DELETE CONFIGURATION
788793
######################
789794
if configuration and not dry_run:
@@ -807,8 +812,6 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
807812
writer.release()
808813
# END delete configuration
809814

810-
# void our data not to delay invalid access
811-
self._clear_cache()
812815
return self
813816

814817
def set_parent_commit(self, commit, check=True):
@@ -840,10 +843,15 @@ def set_parent_commit(self, commit, check=True):
840843
# END handle checking mode
841844

842845
# update our sha, it could have changed
843-
self.binsha = pctree[self.path].binsha
846+
# If check is False, we might see a parent-commit that doens't even contain the submodule anymore.
847+
# in that case, mark our sha as being NULL
848+
try:
849+
self.binsha = pctree[self.path].binsha
850+
except KeyError:
851+
self.binsha = self.NULL_BIN_SHA
852+
# end
844853

845854
self._clear_cache()
846-
847855
return self
848856

849857
@unbare_repo

git/test/test_submodule.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# This module is part of GitPython and is released under
22
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
3-
import shutil
43
import sys
54
import os
65

@@ -18,8 +17,6 @@
1817
from git.compat import string_types
1918
from git.repo.fun import find_git_dir
2019

21-
from nose import SkipTest
22-
2320
# Change the configuration if possible to prevent the underlying memory manager
2421
# to keep file handles open. On windows we get problems as they are not properly
2522
# closed due to mmap bugs on windows (as it appears)
@@ -46,7 +43,7 @@ def update(self, op, index, max_count, message=''):
4643

4744
class TestSubmodule(TestBase):
4845

49-
k_subm_current = "468cad66ff1f80ddaeee4123c24e4d53a032c00d"
46+
k_subm_current = "c15a6e1923a14bc760851913858a3942a4193cdb"
5047
k_subm_changed = "394ed7006ee5dc8bddfd132b64001d5dfc0ffdd3"
5148
k_no_subm_tag = "0.1.6"
5249

@@ -67,7 +64,7 @@ def _do_base_tests(self, rwrepo):
6764

6865
assert sm.path == 'git/ext/gitdb'
6966
assert sm.path != sm.name # in our case, we have ids there, which don't equal the path
70-
assert sm.url == 'git://github.com/gitpython-developers/gitdb.git'
67+
assert sm.url.endswith('github.com/gitpython-developers/gitdb.git')
7168
assert sm.branch_path == 'refs/heads/master' # the default ...
7269
assert sm.branch_name == 'master'
7370
assert sm.parent_commit == rwrepo.head.commit
@@ -184,7 +181,9 @@ def _do_base_tests(self, rwrepo):
184181
assert sm.module().head.ref.tracking_branch() is not None
185182

186183
# delete the whole directory and re-initialize
187-
shutil.rmtree(sm.abspath)
184+
assert len(sm.children()) != 0
185+
# shutil.rmtree(sm.abspath)
186+
sm.remove(force=True, configuration=False)
188187
assert len(sm.children()) == 0
189188
# dry-run does nothing
190189
sm.update(dry_run=True, recursive=False, progress=prog)
@@ -277,9 +276,12 @@ def _do_base_tests(self, rwrepo):
277276

278277
# enforce the submodule to be checked out at the right spot as well.
279278
csm.update()
279+
assert csm.module_exists()
280+
assert csm.exists()
281+
assert os.path.isdir(csm.module().working_tree_dir)
280282

281283
# this would work
282-
assert sm.remove(dry_run=True) is sm
284+
assert sm.remove(force=True, dry_run=True) is sm
283285
assert sm.module_exists()
284286
sm.remove(force=True, dry_run=True)
285287
assert sm.module_exists()
@@ -291,17 +293,20 @@ def _do_base_tests(self, rwrepo):
291293

292294
# forcibly delete the child repository
293295
prev_count = len(sm.children())
294-
assert csm.remove(force=True) is csm
296+
self.failUnlessRaises(ValueError, csm.remove, force=True)
297+
# We removed sm, which removed all submodules. Howver, the instance we have
298+
# still points to the commit prior to that, where it still existed
299+
csm.set_parent_commit(csm.repo.commit(), check=False)
295300
assert not csm.exists()
296301
assert not csm.module_exists()
297-
assert len(sm.children()) == prev_count - 1
302+
assert len(sm.children()) == prev_count
298303
# now we have a changed index, as configuration was altered.
299304
# fix this
300305
sm.module().index.reset(working_tree=True)
301306

302307
# now delete only the module of the main submodule
303308
assert sm.module_exists()
304-
sm.remove(configuration=False)
309+
sm.remove(configuration=False, force=True)
305310
assert sm.exists()
306311
assert not sm.module_exists()
307312
assert sm.config_reader().get_value('url')
@@ -391,7 +396,6 @@ def _do_base_tests(self, rwrepo):
391396

392397
@with_rw_repo(k_subm_current)
393398
def test_base_rw(self, rwrepo):
394-
raise SkipTest("Disabled as long as it fails and submodule support wasn't overhauled")
395399
self._do_base_tests(rwrepo)
396400

397401
@with_rw_repo(k_subm_current, bare=True)

0 commit comments

Comments
 (0)
0