Skip to content

Commit 18325e8

Browse files
committed
Fixed caching issue where cloned/copied repository has remnants of local branches where it's expected that it's freshly copied, e.g. no local branches
1 parent 98aab16 commit 18325e8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mbed/mbed.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,17 @@ def init(path=None):
587587

588588
def cleanup():
589589
info("Cleaning up Git index")
590-
if os.path.exists(os.path.join('.git', 'logs')):
591-
rmtree_readonly(os.path.join('.git', 'logs'))
590+
pquery([git_cmd, 'checkout', '--detach', 'HEAD'] + ([] if very_verbose else ['-q'])) # detach head so local branches are deletable
591+
branches = []
592+
lines = pquery([git_cmd, 'branch']).strip().splitlines() # fetch all local branches
593+
for line in lines:
594+
if re.match(r'^\*?\s+\((.+)\)$', line):
595+
continue
596+
line = re.sub(r'\s+', '', line)
597+
branches.append(line)
598+
599+
for branch in branches: # delete all local branches so the new repo clone is not poluted
600+
pquery([git_cmd, 'branch', '-D', branch])
592601

593602
def clone(url, name=None, depth=None, protocol=None):
594603
popen([git_cmd, 'clone', formaturl(url, protocol), name] + (['--depth', depth] if depth else []) + (['-v'] if very_verbose else ([] if verbose else ['-q'])))

0 commit comments

Comments
 (0)