From: Frederic Massart Date: Fri, 17 Aug 2012 09:12:04 +0000 (+0800) Subject: Rebase aborts when encounters merging conflicts X-Git-Tag: v0.1~39 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=923ad894e45c31d90ff5c1c5f2d78d5e45a287aa;p=mdk.git Rebase aborts when encounters merging conflicts --- diff --git a/lib/git.py b/lib/git.py index 19e0f23..783e7d1 100644 --- a/lib/git.py +++ b/lib/git.py @@ -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): diff --git a/moodle-rebase.py b/moodle-rebase.py index 68fe3d0..542de2b 100755 --- a/moodle-rebase.py +++ b/moodle-rebase.py @@ -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