Rebase aborts when encounters merging conflicts
authorFrederic Massart <fred@moodle.com>
Fri, 17 Aug 2012 09:12:04 +0000 (17:12 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 17 Aug 2012 09:12:04 +0000 (17:12 +0800)
lib/git.py
moodle-rebase.py

index 19e0f23..783e7d1 100644 (file)
@@ -132,8 +132,15 @@ class Git(object):
                cmd = 'push %s%s %s' % (force, remote, branch)
                return self.execute(cmd)
 
-       def rebase(self, base, branch):
-               cmd = 'rebase %s %s' % (base, branch)
+       def rebase(self, base = None, branch = None, abort = False):
+               cmd = None
+               if abort:
+                       cmd = 'rebase --abort'
+               elif base != None and branch != None:
+                       # Rebase automatically checks out the branch before rebasing
+                       cmd = 'rebase %s %s' % (base, branch)
+               if cmd == None:
+                       raise Exception('Missing arguments for calling rebase')
                return self.execute(cmd)
 
        def remoteBranches(self, remote):
index 68fe3d0..542de2b 100755 (executable)
@@ -65,6 +65,14 @@ for M in Mlist:
        debug('Working on %s' % (M.get('identifier')))
        M.git().fetch('origin')
 
+       # Test if currently in a detached branch
+       if M.git().currentBranch() == 'HEAD':
+               result = M.git().checkout(M.get('stablebranch'))
+               # If we can't checkout the stable branch, that is probably because we are in an unmerged situation
+               if not result:
+                       debug('Error. The repository seem to be on a detached branch. Skipping.')
+                       continue
+
        # Stash
        stash = M.git().stash(untracked=True)
        if stash[0] != 0:
@@ -87,7 +95,12 @@ for M in Mlist:
                result = M.git().rebase(branch=branch, base=base)
                if result[0] != 0:
                        debug('Error while rebasing branch %s on top of %s' % (branch, base))
-                       debug(result[2])
+                       if result[0] == 1 and result[2].strip() == '':
+                               debug('There must be conflicts.')
+                               debug('Aborting... Please rebase manually.')
+                               M.git().rebase(abort=True)
+                       else:
+                               debug(result[2])
                        continue
 
                # Pushing branch