@@ -204,7 +204,7 @@ def _config_parser_constrained(self, read_only):
204204 #{ Edit Interface
205205
206206 @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 ):
208208 """Add a new submodule to the given repository. This will alter the index
209209 as well as the .gitmodules file, but will not create a new commit.
210210 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):
229229 Examples are 'master' or 'feature/new'
230230 :param no_checkout: if True, and if the repository has to be cloned manually,
231231 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.
232234 :return: The newly created submodule instance
233235 :note: works atomically, such that no change will be done if the repository
234236 update fails for instance"""
235237 if repo .bare :
236238 raise InvalidGitRepositoryError ("Cannot add submodules to bare repositories" )
237239 # END handle bare repos
238240
241+ repoType = repoType or git .Repo
242+
239243 path = to_native_path_linux (path )
240244 if path .endswith ('/' ):
241245 path = path [:- 1 ]
@@ -289,7 +293,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
289293 if not branch_is_default :
290294 kwargs ['b' ] = br .name
291295 # END setup checkout-branch
292- mrepo = git . Repo .clone_from (url , path , ** kwargs )
296+ mrepo = repoType .clone_from (url , path , ** kwargs )
293297 # END verify url
294298
295299 # update configuration and index
@@ -315,7 +319,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
315319 return sm
316320
317321 def update (self , recursive = False , init = True , to_latest_revision = False , progress = None ,
318- dry_run = False ):
322+ dry_run = False , ):
319323 """Update the repository of this submodule to point to the checkout
320324 we point at with the binsha of this instance.
321325
@@ -377,7 +381,6 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
377381 if not init :
378382 return self
379383 # END early abort if init is not allowed
380- import git
381384
382385 # there is no git-repository yet - but delete empty paths
383386 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=
393396 # branch according to the remote-HEAD if possible
394397 progress .update (BEGIN | CLONE , 0 , 1 , prefix + "Cloning %s to %s in submodule %r" % (self .url , module_path , self .name ))
395398 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 )
397400 #END handle dry-run
398401 progress .update (END | CLONE , 0 , 1 , prefix + "Done cloning to %s" % module_path )
399402
@@ -779,6 +782,7 @@ def module(self, repoType=None):
779782 # late import to workaround circular dependencies
780783 module_path = self .abspath
781784 repoType = repoType or git .Repo
785+
782786 try :
783787 repo = repoType (module_path )
784788 if repo != self .repo :
0 commit comments