@@ -213,24 +213,26 @@ def report_hook(index, blksize, size):
213213 break
214214 return target
215215 elif parsed_url .scheme in ('git' , 'git+file' , 'git+ssh' , 'git+http' , 'git+https' ):
216- if isdir (target ):
217- with current_directory (target ):
218- shprint (sh .git , 'fetch' , '--tags' , '--recurse-submodules' )
219- if self .version :
220- shprint (sh .git , 'checkout' , self .version )
221- branch = sh .git ('branch' , '--show-current' )
222- if branch :
223- shprint (sh .git , 'pull' )
224- shprint (sh .git , 'pull' , '--recurse-submodules' )
225- shprint (sh .git , 'submodule' , 'update' , '--recursive' )
226- else :
216+ if not isdir (target ):
227217 if url .startswith ('git+' ):
228218 url = url [4 :]
229- shprint ( sh . git , 'clone' , '--recursive' , url , target )
219+ # if 'version' is specified, do a shallow clone
230220 if self .version :
221+ shprint (sh .mkdir , '-p' , target )
231222 with current_directory (target ):
232- shprint (sh .git , 'checkout' , self .version )
233- shprint (sh .git , 'submodule' , 'update' , '--recursive' )
223+ shprint (sh .git , 'init' )
224+ shprint (sh .git , 'remote' , 'add' , 'origin' , url )
225+ else :
226+ shprint (sh .git , 'clone' , '--recursive' , url , target )
227+ with current_directory (target ):
228+ if self .version :
229+ shprint (sh .git , 'fetch' , '--depth' , '1' , 'origin' , self .version )
230+ shprint (sh .git , 'checkout' , self .version )
231+ branch = sh .git ('branch' , '--show-current' )
232+ if branch :
233+ shprint (sh .git , 'pull' )
234+ shprint (sh .git , 'pull' , '--recurse-submodules' )
235+ shprint (sh .git , 'submodule' , 'update' , '--recursive' , '--init' , '--depth' , '1' )
234236 return target
235237
236238 def apply_patch (self , filename , arch , build_dir = None ):
0 commit comments