diff options
-rw-r--r-- | git/objects/submodule/base.py | 11 | ||||
-rw-r--r-- | git/test/test_submodule.py | 14 |
2 files changed, 22 insertions, 3 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index ae45e3db..92b0c8e8 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -238,6 +238,17 @@ class Submodule(util.IndexObject, Iterable, Traversable): path = path[:-1] # END handle trailing slash + if os.path.isabs(path): + working_tree_linux = to_native_path_linux(repo.working_tree_dir) + if not path.startswith(working_tree_linux): + raise ValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'" + % (working_tree_linux, path)) + path = path[len(working_tree_linux) + 1:] + if not path: + raise ValueError("Absolute submodule path '%s' didn't yield a valid relative path" % path) + # end verify converted relative path makes sense + # end convert to a relative path + # assure we never put backslashes into the url, as some operating systems # like it ... if url is not None: diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 524a69bf..75edf6e5 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -586,6 +586,14 @@ class TestSubmodule(TestBase): @with_rw_repo(k_no_subm_tag, bare=False) def test_first_submodule(self, rwrepo): assert len(list(rwrepo.iter_submodules())) == 0 - sm = rwrepo.create_submodule('first', 'submodules/first', rwrepo.git_dir, no_checkout=True) - assert sm.exists() and sm.module_exists() - rwrepo.index.commit("Added submodule") + + for sm_name, sm_path in (('first', 'submodules/first'), + ('second', os.path.join(rwrepo.working_tree_dir, 'submodules/second'))): + sm = rwrepo.create_submodule(sm_name, sm_path, rwrepo.git_dir, no_checkout=True) + assert sm.exists() and sm.module_exists() + rwrepo.index.commit("Added submodule " + sm_name) + # end for each submodule path to add + + self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', os.path.expanduser('~')) + self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail-too', + rwrepo.working_tree_dir + os.path.sep) |