Skip to content

Commit 4474135

Browse files
authored
Merge pull request #462 from screamerbg/f/fix-cache
Fixed caching issue with local branches
2 parents de681c9 + fe1acd4 commit 4474135

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

mbed/mbed.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def _scm(cls):
254254
@staticclass
255255
class Bld(object):
256256
name = 'bld'
257+
default_branch = 'default'
257258

258259
def isurl(url):
259260
m_url = re.match(regex_url_ref, url.strip().replace('\\', '/'))
@@ -373,6 +374,7 @@ def getbranch():
373374
@staticclass
374375
class Hg(object):
375376
name = 'hg'
377+
default_branch = 'default'
376378
ignore_file = os.path.join('.hg', 'hgignore')
377379

378380
def isurl(url):
@@ -573,6 +575,7 @@ def unignore(dest):
573575
@staticclass
574576
class Git(object):
575577
name = 'git'
578+
default_branch = 'master'
576579
ignore_file = os.path.join('.git', 'info', 'exclude')
577580

578581
def isurl(url):
@@ -587,8 +590,17 @@ def init(path=None):
587590

588591
def cleanup():
589592
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])
592604

593605
def clone(url, name=None, depth=None, protocol=None):
594606
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):
10691081
scm.seturl(formaturl(url, protocol))
10701082
scm.cleanup()
10711083
info("Update cached copy from remote repository")
1084+
if not rev:
1085+
rev = scm.default_branch
10721086
scm.update(rev, True)
10731087
main = False
10741088
except (ProcessException, IOError):

0 commit comments

Comments
 (0)