@@ -32,7 +32,7 @@ def _do_base_tests(self, rwrepo):
3232 assert len (Submodule .list_items (rwrepo , self .k_no_subm_tag )) == 0
3333
3434 assert sm .path == 'lib/git/ext/gitdb'
35- assert sm .path == sm .name # for now, this is True
35+ assert sm .path == sm .name # for now, this is True
3636 assert sm .url == 'git://gitorious.org/git-python/gitdb.git'
3737 assert sm .branch .name == 'master' # its unset in this case
3838 assert sm .parent_commit == rwrepo .head .commit
@@ -109,8 +109,6 @@ def _do_base_tests(self, rwrepo):
109109 # no url and no module at path fails
110110 self .failUnlessRaises (ValueError , Submodule .add , rwrepo , "newsubm" , "pathtorepo" , url = None )
111111
112- # TODO: Test no remote url in existing repository
113-
114112 # CONTINUE UPDATE
115113 #################
116114
@@ -123,6 +121,7 @@ def _do_base_tests(self, rwrepo):
123121 os .rmdir (newdir )
124122
125123 assert sm .update () is sm
124+ sm_repopath = sm .path # cache for later
126125 assert sm .module_exists ()
127126 assert isinstance (sm .module (), git .Repo )
128127 assert sm .module ().working_tree_dir == sm .module_path ()
@@ -146,6 +145,7 @@ def _do_base_tests(self, rwrepo):
146145 assert len (sm .children ()) == 1 # its not checked out yet
147146 csm = sm .children ()[0 ]
148147 assert not csm .module_exists ()
148+ csm_repopath = csm .path
149149
150150 # adjust the path of the submodules module to point to the local destination
151151 new_csmclone_path = to_native_path_linux (join_path_native (self .rorepo .working_tree_dir , sm .path , csm .path ))
@@ -233,10 +233,44 @@ def _do_base_tests(self, rwrepo):
233233 assert not sm .exists ()
234234 assert not sm .module_exists ()
235235
236+ assert len (rwrepo .submodules ) == 0
237+
236238 # ADD NEW SUBMODULE
237239 ###################
238- # raise if url does not match remote url of existing repo
240+ # add a simple remote repo - trailing slashes are no problem
241+ smid = "newsub"
242+ osmid = "othersub"
243+ nsm = Submodule .add (rwrepo , smid , sm_repopath , new_smclone_path , None , no_checkout = True )
244+ assert nsm .name == smid
245+ assert nsm .module_exists ()
246+ assert nsm .exists ()
247+ # its not checked out
248+ assert not os .path .isfile (join_path_native (nsm .module ().working_tree_dir , Submodule .k_modules_file ))
249+ assert len (rwrepo .submodules ) == 1
250+
251+ # add another submodule, but into the root, not as submodule
252+ osm = Submodule .add (rwrepo , osmid , csm_repopath , new_csmclone_path , Submodule .k_head_default )
253+ assert osm != nsm
254+ assert osm .module_exists ()
255+ assert osm .exists ()
256+ assert os .path .isfile (join_path_native (osm .module ().working_tree_dir , 'setup.py' ))
257+
258+ assert len (rwrepo .submodules ) == 2
259+
260+ # commit the changes, just to finalize the operation
261+ rwrepo .index .commit ("my submod commit" )
262+ assert len (rwrepo .submodules ) == 2
239263
264+ # if a submodule's repo has no remotes, it can't be added without an explicit url
265+ osmod = osm .module ()
266+ # needs update as the head changed, it thinks its in the history
267+ # of the repo otherwise
268+ osm ._parent_commit = rwrepo .head .commit
269+ osm .remove (module = False )
270+ for remote in osmod .remotes :
271+ remote .remove (osmod , remote .name )
272+ assert not osm .exists ()
273+ self .failUnlessRaises (ValueError , Submodule .add , rwrepo , osmid , csm_repopath , url = None )
240274 # END handle bare mode
241275
242276
0 commit comments