@@ -32,7 +32,7 @@ def _do_base_tests(self, rwrepo):
32
32
assert len (Submodule .list_items (rwrepo , self .k_no_subm_tag )) == 0
33
33
34
34
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
36
36
assert sm .url == 'git://gitorious.org/git-python/gitdb.git'
37
37
assert sm .branch .name == 'master' # its unset in this case
38
38
assert sm .parent_commit == rwrepo .head .commit
@@ -109,8 +109,6 @@ def _do_base_tests(self, rwrepo):
109
109
# no url and no module at path fails
110
110
self .failUnlessRaises (ValueError , Submodule .add , rwrepo , "newsubm" , "pathtorepo" , url = None )
111
111
112
- # TODO: Test no remote url in existing repository
113
-
114
112
# CONTINUE UPDATE
115
113
#################
116
114
@@ -123,6 +121,7 @@ def _do_base_tests(self, rwrepo):
123
121
os .rmdir (newdir )
124
122
125
123
assert sm .update () is sm
124
+ sm_repopath = sm .path # cache for later
126
125
assert sm .module_exists ()
127
126
assert isinstance (sm .module (), git .Repo )
128
127
assert sm .module ().working_tree_dir == sm .module_path ()
@@ -146,6 +145,7 @@ def _do_base_tests(self, rwrepo):
146
145
assert len (sm .children ()) == 1 # its not checked out yet
147
146
csm = sm .children ()[0 ]
148
147
assert not csm .module_exists ()
148
+ csm_repopath = csm .path
149
149
150
150
# adjust the path of the submodules module to point to the local destination
151
151
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):
233
233
assert not sm .exists ()
234
234
assert not sm .module_exists ()
235
235
236
+ assert len (rwrepo .submodules ) == 0
237
+
236
238
# ADD NEW SUBMODULE
237
239
###################
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
239
263
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 )
240
274
# END handle bare mode
241
275
242
276
0 commit comments