@@ -204,7 +204,7 @@ def _config_parser_constrained(self, read_only):
204
204
#{ Edit Interface
205
205
206
206
@classmethod
207
- def add (cls , repo , name , path , url = None , branch = None , no_checkout = False ):
207
+ def add (cls , repo , name , path , url = None , branch = None , no_checkout = False , repoType = None ):
208
208
"""Add a new submodule to the given repository. This will alter the index
209
209
as well as the .gitmodules file, but will not create a new commit.
210
210
If the submodule already exists, no matter if the configuration differs
@@ -229,13 +229,17 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
229
229
Examples are 'master' or 'feature/new'
230
230
:param no_checkout: if True, and if the repository has to be cloned manually,
231
231
no checkout will be performed
232
+ :param repoType: The repository type to use. It must provide the clone_from method.
233
+ If None, the default implementation is used.
232
234
:return: The newly created submodule instance
233
235
:note: works atomically, such that no change will be done if the repository
234
236
update fails for instance"""
235
237
if repo .bare :
236
238
raise InvalidGitRepositoryError ("Cannot add submodules to bare repositories" )
237
239
# END handle bare repos
238
240
241
+ repoType = repoType or git .Repo
242
+
239
243
path = to_native_path_linux (path )
240
244
if path .endswith ('/' ):
241
245
path = path [:- 1 ]
@@ -289,7 +293,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
289
293
if not branch_is_default :
290
294
kwargs ['b' ] = br .name
291
295
# END setup checkout-branch
292
- mrepo = git . Repo .clone_from (url , path , ** kwargs )
296
+ mrepo = repoType .clone_from (url , path , ** kwargs )
293
297
# END verify url
294
298
295
299
# update configuration and index
@@ -315,7 +319,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
315
319
return sm
316
320
317
321
def update (self , recursive = False , init = True , to_latest_revision = False , progress = None ,
318
- dry_run = False ):
322
+ dry_run = False , ):
319
323
"""Update the repository of this submodule to point to the checkout
320
324
we point at with the binsha of this instance.
321
325
@@ -377,7 +381,6 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
377
381
if not init :
378
382
return self
379
383
# END early abort if init is not allowed
380
- import git
381
384
382
385
# there is no git-repository yet - but delete empty paths
383
386
module_path = join_path_native (self .repo .working_tree_dir , self .path )
@@ -393,7 +396,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
393
396
# branch according to the remote-HEAD if possible
394
397
progress .update (BEGIN | CLONE , 0 , 1 , prefix + "Cloning %s to %s in submodule %r" % (self .url , module_path , self .name ))
395
398
if not dry_run :
396
- mrepo = git . Repo .clone_from (self .url , module_path , n = True )
399
+ mrepo = type ( self . repo ) .clone_from (self .url , module_path , n = True )
397
400
#END handle dry-run
398
401
progress .update (END | CLONE , 0 , 1 , prefix + "Done cloning to %s" % module_path )
399
402
@@ -779,6 +782,7 @@ def module(self, repoType=None):
779
782
# late import to workaround circular dependencies
780
783
module_path = self .abspath
781
784
repoType = repoType or git .Repo
785
+
782
786
try :
783
787
repo = repoType (module_path )
784
788
if repo != self .repo :
0 commit comments