Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4ce247

Browse files
committed
Basic submodule tests are working once again !
After all, it was easier than expected. It seems that previous assertionsthe test made should have never been true to begin with. Thus we mighthave improved the test thanks to our improved implementation.Fixesgitpython-developers#233
1 parentc15a6e1 commitd4ce247

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-
ifnotdry_runandos.path.isdir(module_path):
461+
checkout_module_abspath=self.abspath
462+
ifnotdry_runandos.path.isdir(checkout_module_abspath):
463463
try:
464-
os.rmdir(module_path)
464+
os.rmdir(checkout_module_abspath)
465465
exceptOSError:
466-
raiseOSError("Module directory at %r does already exist and is non-empty"%module_path)
466+
raiseOSError("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
ifnotdry_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
ifnotdry_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+
ifnotdry_run:
790+
self._clear_cache()
791+
787792
# DELETE CONFIGURATION
788793
######################
789794
ifconfigurationandnotdry_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
returnself
813816

814817
defset_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+
exceptKeyError:
851+
self.binsha=self.NULL_BIN_SHA
852+
# end
844853

845854
self._clear_cache()
846-
847855
returnself
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-
importshutil
43
importsys
54
importos
65

@@ -18,8 +17,6 @@
1817
fromgit.compatimportstring_types
1918
fromgit.repo.funimportfind_git_dir
2019

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

186183
# delete the whole directory and re-initialize
187-
shutil.rmtree(sm.abspath)
184+
assertlen(sm.children())!=0
185+
# shutil.rmtree(sm.abspath)
186+
sm.remove(force=True,configuration=False)
188187
assertlen(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+
assertcsm.module_exists()
280+
assertcsm.exists()
281+
assertos.path.isdir(csm.module().working_tree_dir)
280282

281283
# this would work
282-
assertsm.remove(dry_run=True)issm
284+
assertsm.remove(force=True,dry_run=True)issm
283285
assertsm.module_exists()
284286
sm.remove(force=True,dry_run=True)
285287
assertsm.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-
assertcsm.remove(force=True)iscsm
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
assertnotcsm.exists()
296301
assertnotcsm.module_exists()
297-
assertlen(sm.children())==prev_count-1
302+
assertlen(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
assertsm.module_exists()
304-
sm.remove(configuration=False)
309+
sm.remove(configuration=False,force=True)
305310
assertsm.exists()
306311
assertnotsm.module_exists()
307312
assertsm.config_reader().get_value('url')
@@ -391,7 +396,6 @@ def _do_base_tests(self, rwrepo):
391396

392397
@with_rw_repo(k_subm_current)
393398
deftest_base_rw(self,rwrepo):
394-
raiseSkipTest("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)

[8]ページ先頭

©2009-2025 Movatter.jp