Commits

Graham Helliwell committed ffb35c1

Raise errors in all cases. This has the side effect of requiring far less indentation, and making it clear that the sync is not successful.

Comments (0)

Files changed (1)

         self.source = source
 
     def dosync(self, opts):
-        '''pull changes from a remote repository, merge new changes if needed.
+        """pull changes from a remote repository, merge new changes if needed.
 
         This finds all changes from the repository at the specified path
         or URL and adds them to the local repository.
         See :hg:`help dates` for a list of formats valid for -d/--date.
 
         Returns 0 on success.
-        '''
+        """
 
         ui = self.ui
         repo = self.repo
             mod, add, rem, del_ = repo.status()[:4]
 
             if mod or add or rem or del_:
-                ui.warn('outstanding uncommitted changes, push skipped, not in sync\n')
-                return 0
+                raise util.Abort('outstanding uncommitted changes, push skipped, not in sync\n')
 
 
             bheads = repo.branchheads(branch)
                           (len(bheads) - 1))
                 raise util.Abort('push skipped, not in sync\n')
 
-            err = False
-
             # Is this a simple fast-forward along the current branch?
             newheads = repo.branchheads(branch)
             newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
             if len(newheads) == 1 and len(newchildren) and  newchildren[0] != parent:
                 ui.status('updating local repository')
                 updatefailed =  hg.update(repo, newchildren[0]) #Returns true if unresolved conflicts exist
-                if updatefailed :
+                if updatefailed:
                     ui.status('merge conflicts occurred, update skipped\n')
                     raise util.Abort('push skipped, not in sync\n')
             elif len(newheads) > 1:
-            # Otherwise, let's merge.
-                if newheads:
-                    # By default, we consider the repository we're pulling
-                    # *from* as authoritative, so we merge our changes into
-                    # theirs.
-                    if opts['switch_parent']:
-                        firstparent, secondparent = parent, newheads[0]
+                # Otherwise, let's merge.
+                # By default, we consider the repository we're pulling
+                # *from* as authoritative, so we merge our changes into
+                # theirs.
+                if opts['switch_parent']:
+                    firstparent, secondparent = parent, newheads[0]
+                else:
+                    firstparent, secondparent = newheads[0], parent
+                    self.updateClean(firstparent)
+
+                ui.status(_('merging with %d:%s\n') %
+                          (repo.changelog.rev(secondparent), short(secondparent)))
+                # We want ui.merge internal:prompt
+                if not hg.merge(repo, secondparent, remind=False):
+                    ui.status('')
+                    if not ui.promptchoice(_('Merge failed, do you want to revert [Y/n]: '), ['&Yes', '&No']):
+                        self.updateClean(firstparent)
+                        raise util.Abort('merge failed and reverted, please merge remaining heads manually and sync again')
                     else:
-                        firstparent, secondparent = newheads[0], parent
-                        self.updateClean(firstparent)
-                    ui.status(_('merging with %d:%s\n') %
-                              (repo.changelog.rev(secondparent), short(secondparent)))
-                    # We want ui.merge internal:prompt
-                    err = hg.merge(repo, secondparent, remind=False)
-                    if err:
-                        self.updateClean(firstparent)
+                        raise util.Abort('merge failed, please resolve remaining merge conflicts manually, commit and sync again')
 
+                # we don't translate commit messages
+                message = (cmdutil.logmessage(ui, opts) or
+                           ('Automated merge with %s' %
+                            urllib2.unquote(util.removeauth(remoterepository.url()))))
+                editor = cmdutil.commiteditor
+                if opts.get('edit'):
+                    editor = cmdutil.commitforceeditor
+                n = repo.commit(message, opts['user'], opts['date'], editor=editor)
+                ui.status(_('new changeset %d:%s merges remote changes '
+                            'with local\n') % (repo.changelog.rev(n),
+                                               short(n)))
 
-                if not err:
-                    # we don't translate commit messages
-                    message = (cmdutil.logmessage(ui, opts) or
-                               ('Automated merge with %s' %
-                                urllib2.unquote(util.removeauth(remoterepository.url()))))
-                    editor = cmdutil.commiteditor
-                    if opts.get('edit'):
-                        editor = cmdutil.commitforceeditor
-                    n = repo.commit(message, opts['user'], opts['date'], editor=editor)
-                    ui.status(_('new changeset %d:%s merges remote changes '
-                                'with local\n') % (repo.changelog.rev(n),
-                                                   short(n)))
+            ui.status(_('pushing to %s\n') % util.hidepassword(ui.expandpath(self.source)))
+            if repo.push(remoterepository) == 1:
+                raise util.Abort('push failed, please check your synchronization settings')
+            ui.status('push complete\n')
+            ui.status('sync complete\n')
 
 
-            if not err:
-                ui.status(_('pushing to %s\n') % util.hidepassword(ui.expandpath(self.source)))
-                err = (repo.push(remoterepository) == 1)
-                ui.status('push complete\n')
-            return err
-
         finally:
             release(lock, wlock)