@@ -254,6 +254,7 @@ def _scm(cls):
254
254
@staticclass
255
255
class Bld (object ):
256
256
name = 'bld'
257
+ default_branch = 'default'
257
258
258
259
def isurl (url ):
259
260
m_url = re .match (regex_url_ref , url .strip ().replace ('\\ ' , '/' ))
@@ -373,6 +374,7 @@ def getbranch():
373
374
@staticclass
374
375
class Hg (object ):
375
376
name = 'hg'
377
+ default_branch = 'default'
376
378
ignore_file = os .path .join ('.hg' , 'hgignore' )
377
379
378
380
def isurl (url ):
@@ -573,6 +575,7 @@ def unignore(dest):
573
575
@staticclass
574
576
class Git (object ):
575
577
name = 'git'
578
+ default_branch = 'master'
576
579
ignore_file = os .path .join ('.git' , 'info' , 'exclude' )
577
580
578
581
def isurl (url ):
@@ -587,8 +590,17 @@ def init(path=None):
587
590
588
591
def cleanup ():
589
592
info ("Cleaning up Git index" )
590
- if os .path .exists (os .path .join ('.git' , 'logs' )):
591
- rmtree_readonly (os .path .join ('.git' , 'logs' ))
593
+ pquery ([git_cmd , 'checkout' , '--detach' , 'HEAD' ] + ([] if very_verbose else ['-q' ])) # detach head so local branches are deletable
594
+ branches = []
595
+ lines = pquery ([git_cmd , 'branch' ]).strip ().splitlines () # fetch all local branches
596
+ for line in lines :
597
+ if re .match (r'^\*?\s+\((.+)\)$' , line ):
598
+ continue
599
+ line = re .sub (r'\s+' , '' , line )
600
+ branches .append (line )
601
+
602
+ for branch in branches : # delete all local branches so the new repo clone is not poluted
603
+ pquery ([git_cmd , 'branch' , '-D' , branch ])
592
604
593
605
def clone (url , name = None , depth = None , protocol = None ):
594
606
popen ([git_cmd , 'clone' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
@@ -1069,6 +1081,8 @@ def clone(self, url, path, rev=None, depth=None, protocol=None, **kwargs):
1069
1081
scm .seturl (formaturl (url , protocol ))
1070
1082
scm .cleanup ()
1071
1083
info ("Update cached copy from remote repository" )
1084
+ if not rev :
1085
+ rev = scm .default_branch
1072
1086
scm .update (rev , True )
1073
1087
main = False
1074
1088
except (ProcessException , IOError ):
0 commit comments