Skip to content

Commit f4d7590

Browse files
committed
introduce Git.merge() routine
1 parent c4f24ce commit f4d7590

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mbed/mbed.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ def remove(file):
443443
def commit():
444444
popen([git_cmd, 'commit', '-a'] + (['-v'] if verbose else ['-q']))
445445

446+
def merge(repo, dest):
447+
log("Merging \"%s\" with \"%s\" from \"%s\"" % (repo.name, dest, repo.url))
448+
popen([git_cmd, 'merge', dest] + (['-v'] if verbose else ['-q']))
449+
446450
def publish(repo, all=None):
447451
if all:
448452
popen([git_cmd, 'push', '--all'] + (['-v'] if verbose else ['-q']))
@@ -475,8 +479,9 @@ def checkout(repo, hash, clean=False):
475479
if Git.isdetached(): # try to find associated refs to avoid detached state
476480
refs = Git.getrefs(hash)
477481
for ref in refs: # re-associate with a local or remote branch (hash is the same)
478-
log("Hash \"%s\" match a branch reference. Re-associating with branch (it's the same hash)" % hash)
479-
popen([git_cmd, 'checkout', re.sub(r'^(.*?)\/(.*?)$', r'\2', ref)] + ([] if verbose else ['-q']))
482+
branch = re.sub(r'^(.*?)\/(.*?)$', r'\2', ref)
483+
log("Hash \"%s\" matches a branch \"%s\"reference. Re-associating with branch" % (hash, branch))
484+
popen([git_cmd, 'checkout', branch] + ([] if verbose else ['-q']))
480485
break
481486

482487
def update(repo, hash=None, clean=False):
@@ -490,8 +495,7 @@ def update(repo, hash=None, clean=False):
490495
remote = Git.getremote()
491496
branch = Git.getbranch()
492497
if remote and branch:
493-
log("Merging \"%s\" with remote branch %s/%s from \"%s\"" % (repo.name, remote, branch, repo.url))
494-
popen([git_cmd, 'merge', "%s/%s" % (remote, branch)] + (['-v'] if verbose else ['-q']))
498+
Git.merge(repo, '%s/%s' % (remote, branch))
495499
else:
496500
err = "Unable to update \"%s\" in \"%s\".\n" % (repo.name, repo.path)
497501
if not remote:

0 commit comments

Comments
 (0)