@@ -281,7 +281,7 @@ def cleanup():
281
281
else :
282
282
shutil .rmtree (fl )
283
283
284
- def clone (url , path = None , depth = None , protocol = None ):
284
+ def clone (url , path = None , rev = None , depth = None , protocol = None ):
285
285
m = Bld .isurl (url )
286
286
if not m :
287
287
raise ProcessException (1 , "Not a library build URL" )
@@ -395,7 +395,7 @@ def init(path=None):
395
395
def cleanup ():
396
396
return True
397
397
398
- def clone (url , name = None , depth = None , protocol = None ):
398
+ def clone (url , name = None , rev = None , depth = None , protocol = None ):
399
399
popen ([hg_cmd , 'clone' , formaturl (url , protocol ), name ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
400
400
401
401
def add (dest ):
@@ -607,8 +607,24 @@ def cleanup():
607
607
for branch in branches : # delete all local branches so the new repo clone is not poluted
608
608
pquery ([git_cmd , 'branch' , '-D' , branch ])
609
609
610
- def clone (url , name = None , depth = None , protocol = None ):
611
- popen ([git_cmd , 'clone' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
610
+ def clone (url , path , rev = None , depth = None , protocol = None , name = None ):
611
+ result = pquery ([git_cmd , "ls-remote" , url , (rev if rev else "HEAD" )])
612
+
613
+ if result and rev :
614
+ repo_name = url .split ('/' )[- 1 ]
615
+ if '.git' in repo_name :
616
+ repo_name = repo_name [:- 4 ]
617
+
618
+ os .mkdir (repo_name )
619
+
620
+ with cd (repo_name ):
621
+ Git .init ()
622
+ Git .fetch (url = url , rev = rev , depth = depth )
623
+ Git .checkout ('FETCH_HEAD' )
624
+ popen ([git_cmd , 'remote' , 'add' , 'origin' , url ])
625
+
626
+ else :
627
+ popen ([git_cmd , 'clone' , formaturl (url , protocol ), path ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
612
628
613
629
def add (dest ):
614
630
info ("Adding reference " + dest )
@@ -642,9 +658,12 @@ def publish(all_refs=None):
642
658
if not branch :
643
659
error (err + "Working set is not on a branch." , 1 )
644
660
645
- def fetch ():
661
+ def fetch (url = None , rev = None , depth = None ):
646
662
info ("Fetching revisions from remote repository to \" %s\" " % os .path .basename (os .getcwd ()))
647
- popen ([git_cmd , 'fetch' , '--all' , '--tags' ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
663
+ if url :
664
+ popen ([git_cmd , 'fetch' , '--tags' ] + ([url ] if url else []) + ([rev ] if rev else []) + (["--depth" , depth ] if depth else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
665
+ else :
666
+ popen ([git_cmd , 'fetch' , '--tags' , '--all' ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
648
667
649
668
def discard (clean_files = False ):
650
669
info ("Discarding local changes in \" %s\" " % os .path .basename (os .getcwd ()))
@@ -1098,7 +1117,7 @@ def clone(self, url, path, rev=None, depth=None, protocol=None, **kwargs):
1098
1117
# Main clone routine if the clone with cache ref failed (might occur if cache ref is dirty)
1099
1118
if main :
1100
1119
try :
1101
- scm .clone (url , path , depth = depth , protocol = protocol , ** kwargs )
1120
+ scm .clone (url , path , rev = rev , depth = depth , protocol = protocol , ** kwargs )
1102
1121
except ProcessException :
1103
1122
if os .path .isdir (path ):
1104
1123
rmtree_readonly (path )
@@ -1786,7 +1805,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1786
1805
with cd (repo .path ):
1787
1806
Program (repo .path ).set_root ()
1788
1807
try :
1789
- if repo .rev and repo .getrev () != repo .rev :
1808
+ if repo .rev and repo .getrev () != repo .rev and not depth :
1790
1809
repo .checkout (repo .rev , True )
1791
1810
except ProcessException as e :
1792
1811
err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
0 commit comments