Skip to content

Commit 609a46a

Browse files
committed
submodule: removed module_path method as it is implemented in the abspath property alrdeady
Improved submodule move tests
1 parent a1e6234 commit 609a46a

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lib/git/objects/submodule.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
275275
branch_is_default = branch is None
276276
if has_module and url is not None:
277277
if url not in [r.url for r in sm.module().remotes]:
278-
raise ValueError("Specified URL '%s' does not match any remote url of the repository at '%s'" % (url, sm.module_path()))
278+
raise ValueError("Specified URL '%s' does not match any remote url of the repository at '%s'" % (url, sm.abspath))
279279
# END check url
280280
# END verify urls match
281281

@@ -287,7 +287,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
287287
mrepo = sm.module()
288288
urls = [r.url for r in mrepo.remotes]
289289
if not urls:
290-
raise ValueError("Didn't find any remote url in repository at %s" % sm.module_path())
290+
raise ValueError("Didn't find any remote url in repository at %s" % sm.abspath)
291291
# END verify we have url
292292
url = urls[0]
293293
else:
@@ -493,7 +493,7 @@ def move(self, module_path):
493493
#END handle existance
494494

495495
# move the module into place if possible
496-
cur_path = self.module_path()
496+
cur_path = self.abspath
497497
if os.path.exists(cur_path):
498498
os.renames(cur_path, dest_path)
499499
#END move physical module
@@ -522,8 +522,6 @@ def move(self, module_path):
522522

523523
return self
524524

525-
526-
527525
@unbare_repo
528526
def remove(self, module=True, force=False, configuration=True, dry_run=False):
529527
"""Remove this submodule from the repository. This will remove our entry
@@ -559,7 +557,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
559557
# take the fast lane and just delete everything in our module path
560558
# TODO: If we run into permission problems, we have a highly inconsistent
561559
# state. Delete the .git folders last, start with the submodules first
562-
mp = self.module_path()
560+
mp = self.abspath
563561
method = None
564562
if os.path.islink(mp):
565563
method = os.remove
@@ -691,7 +689,7 @@ def module(self):
691689
:raise InvalidGitRepositoryError: if a repository was not available. This could
692690
also mean that it was not yet initialized"""
693691
# late import to workaround circular dependencies
694-
module_path = self.module_path()
692+
module_path = self.abspath
695693
try:
696694
repo = git.Repo(module_path)
697695
if repo != self.repo:
@@ -703,10 +701,6 @@ def module(self):
703701
raise InvalidGitRepositoryError("Repository at %r was not yet checked out" % module_path)
704702
# END handle exceptions
705703

706-
def module_path(self):
707-
""":return: full path to the root of our module. It is relative to the filesystem root"""
708-
return join_path_native(self.repo.working_tree_dir, self.path)
709-
710704
def module_exists(self):
711705
""":return: True if our module exists and is a valid git repository. See module() method"""
712706
try:

test/git/test_submodule.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _do_base_tests(self, rwrepo):
113113
#################
114114

115115
# lets update it - its a recursive one too
116-
newdir = os.path.join(sm.module_path(), 'dir')
116+
newdir = os.path.join(sm.abspath, 'dir')
117117
os.makedirs(newdir)
118118

119119
# update fails if the path already exists non-empty
@@ -124,7 +124,7 @@ def _do_base_tests(self, rwrepo):
124124
sm_repopath = sm.path # cache for later
125125
assert sm.module_exists()
126126
assert isinstance(sm.module(), git.Repo)
127-
assert sm.module().working_tree_dir == sm.module_path()
127+
assert sm.module().working_tree_dir == sm.abspath
128128

129129
# INTERLEAVE ADD TEST
130130
#####################
@@ -139,7 +139,7 @@ def _do_base_tests(self, rwrepo):
139139
assert sm.module().head.ref.tracking_branch() is not None
140140

141141
# delete the whole directory and re-initialize
142-
shutil.rmtree(sm.module_path())
142+
shutil.rmtree(sm.abspath)
143143
sm.update(recursive=False)
144144
assert len(list(rwrepo.iter_submodules())) == 2
145145
assert len(sm.children()) == 1 # its not checked out yet
@@ -273,11 +273,29 @@ def _do_base_tests(self, rwrepo):
273273

274274
# rename a module
275275
nmp = join_path_native("new", "module", "dir") + "/" # new module path
276+
pmp = nsm.path
277+
abspmp = nsm.abspath
276278
assert nsm.move(nmp) is nsm
277279
nmp = nmp[:-1] # cut last /
278280
assert nsm.path == nmp
279281
assert rwrepo.submodules[0].path == nmp
280282

283+
# move it back - but there is a file now - this doesn't work
284+
# as the empty directories where removed.
285+
self.failUnlessRaises(IOError, open, abspmp, 'w')
286+
287+
mpath = 'newsubmodule'
288+
absmpath = join_path_native(rwrepo.working_tree_dir, mpath)
289+
open(absmpath, 'w').write('')
290+
self.failUnlessRaises(ValueError, nsm.move, mpath)
291+
os.remove(absmpath)
292+
293+
# now it works, as we just move it back
294+
nsm.move(pmp)
295+
assert nsm.path == pmp
296+
assert rwrepo.submodules[0].path == pmp
297+
298+
# TODO lowprio: test remaining exceptions ... for now its okay, the code looks right
281299

282300
# REMOVE 'EM ALL
283301
################

0 commit comments

Comments
 (0)