summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/objects/submodule.py16
-rw-r--r--test/git/test_submodule.py24
2 files changed, 26 insertions, 14 deletions
diff --git a/lib/git/objects/submodule.py b/lib/git/objects/submodule.py
index 8a1ab6af..51453820 100644
--- a/lib/git/objects/submodule.py
+++ b/lib/git/objects/submodule.py
@@ -275,7 +275,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
branch_is_default = branch is None
if has_module and url is not None:
if url not in [r.url for r in sm.module().remotes]:
- raise ValueError("Specified URL '%s' does not match any remote url of the repository at '%s'" % (url, sm.module_path()))
+ raise ValueError("Specified URL '%s' does not match any remote url of the repository at '%s'" % (url, sm.abspath))
# END check url
# END verify urls match
@@ -287,7 +287,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
mrepo = sm.module()
urls = [r.url for r in mrepo.remotes]
if not urls:
- raise ValueError("Didn't find any remote url in repository at %s" % sm.module_path())
+ raise ValueError("Didn't find any remote url in repository at %s" % sm.abspath)
# END verify we have url
url = urls[0]
else:
@@ -493,7 +493,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
#END handle existance
# move the module into place if possible
- cur_path = self.module_path()
+ cur_path = self.abspath
if os.path.exists(cur_path):
os.renames(cur_path, dest_path)
#END move physical module
@@ -522,8 +522,6 @@ class Submodule(base.IndexObject, Iterable, Traversable):
return self
-
-
@unbare_repo
def remove(self, module=True, force=False, configuration=True, dry_run=False):
"""Remove this submodule from the repository. This will remove our entry
@@ -559,7 +557,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
# take the fast lane and just delete everything in our module path
# TODO: If we run into permission problems, we have a highly inconsistent
# state. Delete the .git folders last, start with the submodules first
- mp = self.module_path()
+ mp = self.abspath
method = None
if os.path.islink(mp):
method = os.remove
@@ -691,7 +689,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
:raise InvalidGitRepositoryError: if a repository was not available. This could
also mean that it was not yet initialized"""
# late import to workaround circular dependencies
- module_path = self.module_path()
+ module_path = self.abspath
try:
repo = git.Repo(module_path)
if repo != self.repo:
@@ -703,10 +701,6 @@ class Submodule(base.IndexObject, Iterable, Traversable):
raise InvalidGitRepositoryError("Repository at %r was not yet checked out" % module_path)
# END handle exceptions
- def module_path(self):
- """:return: full path to the root of our module. It is relative to the filesystem root"""
- return join_path_native(self.repo.working_tree_dir, self.path)
-
def module_exists(self):
""":return: True if our module exists and is a valid git repository. See module() method"""
try:
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py
index 20826f70..212b1e1d 100644
--- a/test/git/test_submodule.py
+++ b/test/git/test_submodule.py
@@ -113,7 +113,7 @@ class TestSubmodule(TestBase):
#################
# lets update it - its a recursive one too
- newdir = os.path.join(sm.module_path(), 'dir')
+ newdir = os.path.join(sm.abspath, 'dir')
os.makedirs(newdir)
# update fails if the path already exists non-empty
@@ -124,7 +124,7 @@ class TestSubmodule(TestBase):
sm_repopath = sm.path # cache for later
assert sm.module_exists()
assert isinstance(sm.module(), git.Repo)
- assert sm.module().working_tree_dir == sm.module_path()
+ assert sm.module().working_tree_dir == sm.abspath
# INTERLEAVE ADD TEST
#####################
@@ -139,7 +139,7 @@ class TestSubmodule(TestBase):
assert sm.module().head.ref.tracking_branch() is not None
# delete the whole directory and re-initialize
- shutil.rmtree(sm.module_path())
+ shutil.rmtree(sm.abspath)
sm.update(recursive=False)
assert len(list(rwrepo.iter_submodules())) == 2
assert len(sm.children()) == 1 # its not checked out yet
@@ -273,11 +273,29 @@ class TestSubmodule(TestBase):
# rename a module
nmp = join_path_native("new", "module", "dir") + "/" # new module path
+ pmp = nsm.path
+ abspmp = nsm.abspath
assert nsm.move(nmp) is nsm
nmp = nmp[:-1] # cut last /
assert nsm.path == nmp
assert rwrepo.submodules[0].path == nmp
+ # move it back - but there is a file now - this doesn't work
+ # as the empty directories where removed.
+ self.failUnlessRaises(IOError, open, abspmp, 'w')
+
+ mpath = 'newsubmodule'
+ absmpath = join_path_native(rwrepo.working_tree_dir, mpath)
+ open(absmpath, 'w').write('')
+ self.failUnlessRaises(ValueError, nsm.move, mpath)
+ os.remove(absmpath)
+
+ # now it works, as we just move it back
+ nsm.move(pmp)
+ assert nsm.path == pmp
+ assert rwrepo.submodules[0].path == pmp
+
+ # TODO lowprio: test remaining exceptions ... for now its okay, the code looks right
# REMOVE 'EM ALL
################