summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-17 00:28:57 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-17 00:28:57 +0100
commitef48ca5f54fe31536920ec4171596ff8468db5fe (patch)
treea2540d1aad914b68b94e8d34f0490d906f77ac84
parent7b3ef45167e1c2f7d1b7507c13fcedd914f87da9 (diff)
downloadgitpython-ef48ca5f54fe31536920ec4171596ff8468db5fe.tar.gz
Added rest of submodule.add test code which should be pretty much 100% coverage for it
-rw-r--r--lib/git/objects/submodule.py15
-rw-r--r--test/git/test_submodule.py42
2 files changed, 49 insertions, 8 deletions
diff --git a/lib/git/objects/submodule.py b/lib/git/objects/submodule.py
index 586ebeab..e07117a6 100644
--- a/lib/git/objects/submodule.py
+++ b/lib/git/objects/submodule.py
@@ -85,7 +85,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
k_modules_file = '.gitmodules'
k_head_option = 'branch'
k_head_default = 'master'
- k_def_mode = stat.S_IFDIR | stat.S_IFLNK # submodules are directories with link-status
+ k_default_mode = stat.S_IFDIR | stat.S_IFLNK # submodules are directories with link-status
# this is a bogus type for base class compatability
type = 'submodule'
@@ -244,7 +244,7 @@ class Submodule(base.IndexObject, Iterable, Traversable):
# END handle trailing slash
# INSTANTIATE INTERMEDIATE SM
- sm = cls(repo, cls.NULL_BIN_SHA, cls.k_def_mode, path, name)
+ sm = cls(repo, cls.NULL_BIN_SHA, cls.k_default_mode, path, name)
if sm.exists():
# reretrieve submodule from tree
return repo.head.commit.tree[path]
@@ -712,10 +712,17 @@ class Submodule(base.IndexObject, Iterable, Traversable):
# END handle optional information
# get the binsha
+ index = repo.index
try:
sm = rt[p]
except KeyError:
- raise InvalidGitRepositoryError("Gitmodule path %r did not exist in revision of parent commit %s" % (p, parent_commit))
+ # try the index, maybe it was just added
+ try:
+ entry = index.entries[index.entry_key(p, 0)]
+ sm = cls(repo, entry.binsha, entry.mode, entry.path)
+ except KeyError:
+ raise InvalidGitRepositoryError("Gitmodule path %r did not exist in revision of parent commit %s" % (p, parent_commit))
+ # END handle keyerror
# END handle critical error
# fill in remaining info - saves time as it doesn't have to be parsed again
@@ -743,7 +750,7 @@ class RootModule(Submodule):
super(RootModule, self).__init__(
repo,
binsha = self.NULL_BIN_SHA,
- mode = self.k_def_mode,
+ mode = self.k_default_mode,
path = '',
name = self.k_root_name,
parent_commit = repo.head.commit,
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py
index a8f8f2b7..6432fcaf 100644
--- a/test/git/test_submodule.py
+++ b/test/git/test_submodule.py
@@ -32,7 +32,7 @@ class TestSubmodule(TestBase):
assert len(Submodule.list_items(rwrepo, self.k_no_subm_tag)) == 0
assert sm.path == 'lib/git/ext/gitdb'
- assert sm.path == sm.name # for now, this is True
+ assert sm.path == sm.name # for now, this is True
assert sm.url == 'git://gitorious.org/git-python/gitdb.git'
assert sm.branch.name == 'master' # its unset in this case
assert sm.parent_commit == rwrepo.head.commit
@@ -109,8 +109,6 @@ class TestSubmodule(TestBase):
# no url and no module at path fails
self.failUnlessRaises(ValueError, Submodule.add, rwrepo, "newsubm", "pathtorepo", url=None)
- # TODO: Test no remote url in existing repository
-
# CONTINUE UPDATE
#################
@@ -123,6 +121,7 @@ class TestSubmodule(TestBase):
os.rmdir(newdir)
assert sm.update() is sm
+ 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()
@@ -146,6 +145,7 @@ class TestSubmodule(TestBase):
assert len(sm.children()) == 1 # its not checked out yet
csm = sm.children()[0]
assert not csm.module_exists()
+ csm_repopath = csm.path
# adjust the path of the submodules module to point to the local destination
new_csmclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path, csm.path))
@@ -233,10 +233,44 @@ class TestSubmodule(TestBase):
assert not sm.exists()
assert not sm.module_exists()
+ assert len(rwrepo.submodules) == 0
+
# ADD NEW SUBMODULE
###################
- # raise if url does not match remote url of existing repo
+ # add a simple remote repo - trailing slashes are no problem
+ smid = "newsub"
+ osmid = "othersub"
+ nsm = Submodule.add(rwrepo, smid, sm_repopath, new_smclone_path, None, no_checkout=True)
+ assert nsm.name == smid
+ assert nsm.module_exists()
+ assert nsm.exists()
+ # its not checked out
+ assert not os.path.isfile(join_path_native(nsm.module().working_tree_dir, Submodule.k_modules_file))
+ assert len(rwrepo.submodules) == 1
+
+ # add another submodule, but into the root, not as submodule
+ osm = Submodule.add(rwrepo, osmid, csm_repopath, new_csmclone_path, Submodule.k_head_default)
+ assert osm != nsm
+ assert osm.module_exists()
+ assert osm.exists()
+ assert os.path.isfile(join_path_native(osm.module().working_tree_dir, 'setup.py'))
+
+ assert len(rwrepo.submodules) == 2
+
+ # commit the changes, just to finalize the operation
+ rwrepo.index.commit("my submod commit")
+ assert len(rwrepo.submodules) == 2
+ # if a submodule's repo has no remotes, it can't be added without an explicit url
+ osmod = osm.module()
+ # needs update as the head changed, it thinks its in the history
+ # of the repo otherwise
+ osm._parent_commit = rwrepo.head.commit
+ osm.remove(module=False)
+ for remote in osmod.remotes:
+ remote.remove(osmod, remote.name)
+ assert not osm.exists()
+ self.failUnlessRaises(ValueError, Submodule.add, rwrepo, osmid, csm_repopath, url=None)
# END handle bare mode