"""
import logging
-from lib import tools
+from lib import tools, css
from lib.command import Command
from lib.tools import yesOrNo
logging.info('Cherry-picking %s' % (cherry))
result = M2.git().pick(hashes)
if result[0] != 0:
- logging.error('Error while cherry-picking %s in %s.' % (cherry, name))
- logging.debug(result[2])
- if yesOrNo('The cherry-pick might still be in progress, would you like to abort it?'):
- result = M2.git().pick(abort=True)
- if result[0] > 0 and result[0] != 128:
- logging.error('Could not abort the cherry-pick!')
+
+ # Try to resolve the conflicts if any.
+ resolveConflicts = True
+ conflictsResolved = False
+ while resolveConflicts:
+
+ # Check the list of possible conflicting files.
+ conflictingFiles = M2.git().conflictingFiles()
+ if conflictingFiles and len(conflictingFiles) == 1 and 'theme/bootstrapbase/style/moodle.css' in conflictingFiles:
+ logging.info('Conflicts found in bootstrapbase moodle CSS, trying to auto resolve...')
+ cssCompiler = css.Css(M2)
+ if cssCompiler.compile(theme='bootstrapbase', sheets=['moodle']):
+ M2.git().add('theme/bootstrapbase/style/moodle.css')
+ # We need to commit manually to prevent the editor to open.
+ M2.git().commit(filepath='.git/MERGE_MSG')
+ result = M2.git().pick(continu=True)
+ if result[0] == 0:
+ resolveConflicts = False
+ conflictsResolved = True
else:
- stashPop(stash)
- logging.info('')
- continue
+ resolveConflicts = False
+
+ # We still have a dirty repository.
+ if not conflictsResolved:
+ logging.error('Error while cherry-picking %s in %s.' % (cherry, name))
+ logging.debug(result[2])
+ if yesOrNo('The cherry-pick might still be in progress, would you like to abort it?'):
+ result = M2.git().pick(abort=True)
+ if result[0] > 0 and result[0] != 128:
+ logging.error('Could not abort the cherry-pick!')
+ else:
+ stashPop(stash)
+ logging.info('')
+ continue
# Pushing branch
if args.push:
self.setPath(path)
self.setBin(bin)
+ def add(self, path):
+ """Add a file/path"""
+ cmd = 'add %s' % (path)
+ result = self.execute(cmd)
+ return result[0] == 0
+
def addRemote(self, name, remote):
cmd = 'remote add %s %s' % (name, remote)
result = self.execute(cmd)
result = self.execute(cmd)
return result[0] == 0
+ def commit(self, filepath=None):
+ """Wrapper for the commit command"""
+ cmd = 'commit'
+ if filepath:
+ cmd += ' -F %s' % (filepath)
+ result = self.execute(cmd)
+ return result[0] == 0
+
+ def conflictingFiles(self):
+ cmd = 'diff --name-only --diff-filter=U'
+ result = self.execute(cmd)
+ if result[0] == 0:
+ return result[1].strip().split('\n')
+ else:
+ return False
+
def createBranch(self, branch, track=None):
if track != None:
cmd = 'branch --track %s %s' % (branch, track)
messages = self.log(count=count, since=since, path=path, format='%s')
return messages.split('\n')[:-1]
- def pick(self, refs=None, abort=None):
+ def pick(self, refs=None, abort=None, continu=None):
+ """Wrapper for the cherry-pick command
+
+ The typo in the argument 'continu' is voluntarily there, continue is a reserved word.
+ """
args = ''
if refs != None:
if type(refs) == list:
args = refs
elif abort != None:
args = '--abort'
+ elif continu != None:
+ args = '--continue'
cmd = 'cherry-pick %s' % (args)
return self.execute(cmd)