Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c18341

Browse files
committed
Added test-setup which can test all aspects of the (smart) update method
1 parent 8284957 commit 0c18341

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

lib/git/objects/submodule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def find_remote_branch(remotes, branch):
5050
continue
5151
# END exception handling
5252
#END for remote
53-
raise InvalidGitRepositoryError("Didn't find remote branch %r in any of the given remotes", branch
53+
raise InvalidGitRepositoryError("Didn't find remote branch %r in any of the given remotes", branch)
5454

5555
#} END utilities
5656

test/git/test_repo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,6 @@ def test_submodule_update(self, rwrepo):
575575
sm = rwrepo.create_submodule("my_new_sub", "some_path", join_path_native(self.rorepo.working_tree_dir, sm.path))
576576
assert isinstance(sm, Submodule)
577577

578+
# note: the rest of this functionality is tested in test_submodule
579+
578580

test/git/test_submodule.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,13 @@ def test_base_rw(self, rwrepo):
321321
def test_base_bare(self, rwrepo):
322322
self._do_base_tests(rwrepo)
323323

324-
def test_root_module(self):
324+
@with_rw_repo(k_subm_current, bare=False)
325+
def test_root_module(self, rwrepo):
325326
# Can query everything without problems
326327
rm = RootModule(self.rorepo)
327328
assert rm.module() is self.rorepo
328329

330+
# try attributes
329331
rm.binsha
330332
rm.mode
331333
rm.path
@@ -339,8 +341,46 @@ def test_root_module(self):
339341
rm.config_writer()
340342

341343
# deep traversal gitdb / async
342-
assert len(list(rm.traverse())) == 2
344+
rsms = list(rm.traverse())
345+
assert len(rsms) == 2 # gitdb and async, async being a child of gitdb
343346

344-
# cannot set the parent commit as repo name doesn't exist
347+
# cannot set the parent commit as root module's path didn't exist
345348
self.failUnlessRaises(ValueError, rm.set_parent_commit, 'HEAD')
346349

350+
# TEST UPDATE
351+
#############
352+
# setup commit which remove existing, add new and modify existing submodules
353+
rm = RootModule(rwrepo)
354+
assert len(rm.children()) == 1
355+
356+
# modify path
357+
sm = rm.children()[0]
358+
pp = "path/prefix"
359+
sm.config_writer().set_value('path', join_path_native(pp, sm.path))
360+
cpathchange = rwrepo.index.commit("changed sm path")
361+
362+
# add submodule
363+
nsmn = "newsubmodule"
364+
nsmp = "submrepo"
365+
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=join_path_native(self.rorepo.working_tree_dir, rsms[0].path, rsms[1].path))
366+
csmadded = rwrepo.index.commit("Added submodule")
367+
368+
# remove submodule - the previous one
369+
sm.set_parent_commit(csmadded)
370+
assert not sm.remove().exists()
371+
csmremoved = rwrepo.index.commit("Removed submodule")
372+
373+
# change url - to the first repository, this way we have a fast checkout, and a completely different
374+
# repository at the different url
375+
nsm.set_parent_commit(csmremoved)
376+
nsm.config_writer().set_value('url', join_path_native(self.rorepo.working_tree_dir, rsms[0].path))
377+
csmpathchange = rwrepo.index.commit("changed url")
378+
379+
# change branch
380+
nsm.set_parent_commit(csmpathchange)
381+
# the branch used here is an old failure branch which should ideally stay ... lets see how long that works ;)
382+
nbn = 'pack_offset_cache'
383+
assert nsm.branch.name != nbn
384+
nsm.config_writer().set_value(Submodule.k_head_option, nbn)
385+
csmbranchchange = rwrepo.index.commit("changed branch")
386+

0 commit comments

Comments
 (0)