Skip to content

Commit a223c7b

Browse files
committed
Submodule.move() fixed to deal with 'non-gitfile' clones appropriately.
Improved a test to assure multiple update(init=False|True) calls don't throw. Fixes #93
1 parent d4ce247 commit a223c7b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

‎git/objects/submodule/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def move(self, module_path, configuration=True, module=True):
636636
os.renames(cur_path, module_checkout_abspath)
637637
renamed_module = True
638638

639-
if self._need_gitfile_submodules(self.repo.git):
639+
if os.path.isfile(os.path.join(module_checkout_abspath, '.git')):
640640
module_abspath = self._module_abspath(self.repo, self.path, self.name)
641641
self._write_git_file_and_module_config(module_checkout_abspath, module_abspath)
642642
# end handle git file rewrite

‎git/test/test_submodule.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ def _do_base_tests(self, rwrepo):
377377
assert nsm.path == pmp
378378
assert rwrepo.submodules[0].path == pmp
379379

380-
# TODO lowprio: test remaining exceptions ... for now its okay, the code looks right
381-
382380
# REMOVE 'EM ALL
383381
################
384382
# if a submodule's repo has no remotes, it can't be added without an explicit url
@@ -636,8 +634,20 @@ def test_git_submodules(self, rwdir):
636634

637635
assert sm.exists() and sm.module_exists()
638636

639-
# test move and rename
640-
# TODO
637+
clone = git.Repo.clone_from(self._submodule_url(),
638+
os.path.join(parent.working_tree_dir, 'existing-subrepository'))
639+
sm2 = parent.create_submodule('nongit-file-submodule', clone.working_tree_dir)
640+
assert len(parent.submodules) == 2
641+
642+
for _ in range(2):
643+
for init in (False, True):
644+
sm.update(init=init)
645+
sm2.update(init=init)
646+
# end for each init state
647+
# end for each iteration
648+
649+
sm.move(sm.path + '_moved')
650+
sm2.move(sm2.path + '_moved')
641651

642652
@with_rw_directory
643653
def test_git_submodule_compatibility(self, rwdir):

0 commit comments

Comments
 (0)