@@ -122,7 +122,10 @@ def _get_result():
122122 return result
123123
124124 logger .info ('Initializing environment for {}.' .format (repo ))
125- directory = make_strategy ()
125+
126+ directory = tempfile .mkdtemp (prefix = 'repo' , dir = self .directory )
127+ with clean_path_on_failure (directory ):
128+ make_strategy (directory )
126129
127130 # Update our db with the created repo
128131 with self .connect () as db :
@@ -132,50 +135,41 @@ def _get_result():
132135 )
133136 return directory
134137
135- def _perform_safe_clone (self , clone_strategy ):
136- directory = tempfile .mkdtemp (prefix = 'repo' , dir = self .directory )
137- with clean_path_on_failure (directory ):
138- clone_strategy (directory )
139- return directory
140-
141- def _complete_clone (self , repo , ref , directory ):
138+ def _complete_clone (self , ref , git_cmd ):
142139 """Perform a complete clone of a repository and its submodules """
143- env = git .no_git_env ()
144-
145- cmd = ('git' , 'clone' , '--no-checkout' , repo , directory )
146- cmd_output (* cmd , env = env )
147140
148- def _git_cmd (* args ):
149- return cmd_output ('git' , * args , cwd = directory , env = env )
141+ git_cmd ('fetch' , 'origin' )
142+ git_cmd ('checkout' , ref )
143+ git_cmd ('submodule' , 'update' , '--init' , '--recursive' )
150144
151- _git_cmd ('reset' , ref , '--hard' )
152- _git_cmd ('submodule' , 'update' , '--init' , '--recursive' )
153-
154- def _shallow_clone (self , repo , ref , directory ):
145+ def _shallow_clone (self , ref , protocol_version , git_cmd ):
155146 """Perform a shallow clone of a repository and its submodules """
156- env = git .no_git_env ()
157-
158- def _git_cmd (* args ):
159- return cmd_output ('git' , * args , cwd = directory , env = env )
160147
161- _git_cmd ( 'init' , '.' )
162- _git_cmd ( 'remote ' , 'add ' , 'origin' , repo )
163- _git_cmd ( 'fetch ' , 'origin' , ref , '--depth=1' )
164- _git_cmd ( 'checkout ' , ref )
165- _git_cmd ( 'submodule' , 'update' , '--init' , '--recursive' , '--depth=1' )
148+ git_config = 'protocol.version={}' . format ( protocol_version )
149+ git_cmd ( '-c ' , git_config , 'fetch ' , 'origin' , ref , '--depth=1' )
150+ git_cmd ( 'checkout ' , ref )
151+ git_cmd ( '-c ' , git_config , 'submodule' , 'update' , '--init' ,
152+ '--recursive' , '--depth=1' )
166153
167154 def clone (self , repo , ref , deps = ()):
168155 """Clone the given url and checkout the specific ref."""
169156
170- def clone_strategy ():
157+ def clone_strategy (directory ):
158+ env = git .no_git_env ()
159+
160+ def _git_cmd (* args ):
161+ cmd_output ('git' , * args , cwd = directory , env = env )
162+
163+ _git_cmd ('init' , '.' )
164+ _git_cmd ('remote' , 'add' , 'origin' , repo )
165+
171166 try :
172- def shallow_clone (directory ):
173- self ._shallow_clone (repo , ref , directory )
174- return self ._perform_safe_clone (shallow_clone )
167+ self ._shallow_clone (ref , 2 , _git_cmd )
175168 except CalledProcessError :
176- def complete_clone (directory ):
177- self ._complete_clone (repo , ref , directory )
178- return self ._perform_safe_clone (complete_clone )
169+ try :
170+ self ._shallow_clone (ref , 1 , _git_cmd )
171+ except CalledProcessError :
172+ self ._complete_clone (ref , _git_cmd )
179173
180174 return self ._new_repo (repo , ref , deps , clone_strategy )
181175
@@ -202,11 +196,8 @@ def _git_cmd(*args):
202196 _git_cmd ('add' , '.' )
203197 git .commit (repo = directory )
204198
205- def make_strategy ():
206- return self ._perform_safe_clone (make_local_strategy )
207-
208199 return self ._new_repo (
209- 'local' , C .LOCAL_REPO_VERSION , deps , make_strategy ,
200+ 'local' , C .LOCAL_REPO_VERSION , deps , make_local_strategy ,
210201 )
211202
212203 def _create_config_table_if_not_exists (self , db ):
0 commit comments