changeset 11574:6381fa7bfa53

Abort: add a hint argument, printed in the next line inside parenthesis discovery was using a custom made message for this purpose push now returns -1 after aborting, instead of 1 previously
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Thu, 15 Jul 2010 14:41:22 +0200
parents 7ecf4a082c5f
children a5903e612f07
files mercurial/discovery.py mercurial/dispatch.py mercurial/error.py tests/test-push-warn.out
diffstat 4 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/discovery.py	Thu Jul 15 14:40:17 2010 +0200
+++ b/mercurial/discovery.py	Thu Jul 15 14:41:22 2010 +0200
@@ -252,18 +252,16 @@
 
         def fail_multiple_heads(unsynced, branch=None):
             if branch:
-                msg = _("abort: push creates new remote heads"
-                        " on branch '%s'!\n") % branch
+                msg = _("push creates new remote heads "
+                        "on branch '%s'!") % branch
             else:
-                msg = _("abort: push creates new remote heads!\n")
-            repo.ui.warn(msg)
+                msg = _("push creates new remote heads!")
+
             if unsynced:
-                repo.ui.status(_("(you should pull and merge or"
-                                 " use push -f to force)\n"))
+                hint = _("you should pull and merge or use push -f to force")
             else:
-                repo.ui.status(_("(did you forget to merge?"
-                                 " use push -f to force)\n"))
-            return None, 0
+                hint = _("did you forget to merge? use push -f to force")
+            raise util.Abort(msg, hint=hint)
 
         if remote.capable('branchmap'):
             # Check for each named branch if we're creating new remote heads.
@@ -283,12 +281,10 @@
             newbranches = branches - set(remotemap)
             if newbranches and not newbranch: # new branch requires --new-branch
                 branchnames = ', '.join(sorted(newbranches))
-                repo.ui.warn(_("abort: push creates "
-                               "new remote branches: %s!\n")
-                             % branchnames)
-                repo.ui.status(_("(use 'hg push --new-branch' to create new "
-                                 "remote branches)\n"))
-                return None, 0
+                raise util.Abort(_("push creates new remote branches: %s!")
+                                   % branchnames,
+                                 hint=_("use 'hg push --new-branch' to create"
+                                        " new remote branches"))
             branches.difference_update(newbranches)
 
             # 3. Construct the initial oldmap and newmap dicts.
--- a/mercurial/dispatch.py	Thu Jul 15 14:40:17 2010 +0200
+++ b/mercurial/dispatch.py	Thu Jul 15 14:41:22 2010 +0200
@@ -23,6 +23,8 @@
             u.setconfig('ui', 'traceback', 'on')
     except util.Abort, inst:
         sys.stderr.write(_("abort: %s\n") % inst)
+        if inst.hint:
+            sys.stdout.write(_("(%s)\n") % inst.hint)
         return -1
     except error.ParseError, inst:
         if len(inst.args) > 1:
@@ -116,6 +118,8 @@
             commands.help_(ui, 'shortlist')
     except util.Abort, inst:
         ui.warn(_("abort: %s\n") % inst)
+        if inst.hint:
+            ui.status(_("(%s)\n") % inst.hint)
     except ImportError, inst:
         ui.warn(_("abort: %s!\n") % inst)
         m = str(inst).split()[-1]
--- a/mercurial/error.py	Thu Jul 15 14:40:17 2010 +0200
+++ b/mercurial/error.py	Thu Jul 15 14:41:22 2010 +0200
@@ -32,6 +32,9 @@
 
 class Abort(Exception):
     """Raised if a command needs to print an error and exit."""
+    def __init__(self, *args, **kw):
+        Exception.__init__(self, *args)
+        self.hint = kw.get('hint')
 
 class ConfigError(Abort):
     'Exception raised when parsing config files'
--- a/tests/test-push-warn.out	Thu Jul 15 14:40:17 2010 +0200
+++ b/tests/test-push-warn.out	Thu Jul 15 14:41:22 2010 +0200
@@ -37,7 +37,7 @@
 searching for changes
 abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
-1
+255
 pushing to ../c
 searching for changes
 no changes found
@@ -46,12 +46,12 @@
 searching for changes
 abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
-1
+255
 pushing to ../c
 searching for changes
 abort: push creates new remote heads on branch 'default'!
 (did you forget to merge? use push -f to force)
-1
+255
 pushing to ../c
 searching for changes
 adding changesets
@@ -90,29 +90,29 @@
 searching for changes
 abort: push creates new remote branches: c!
 (use 'hg push --new-branch' to create new remote branches)
-1
+255
 pushing to ../f
 searching for changes
 abort: push creates new remote branches: c!
 (use 'hg push --new-branch' to create new remote branches)
-1
+255
 % multiple new branches
 pushing to ../f
 searching for changes
 abort: push creates new remote branches: c, d!
 (use 'hg push --new-branch' to create new remote branches)
-1
+255
 pushing to ../f
 searching for changes
 abort: push creates new remote branches: c, d!
 (use 'hg push --new-branch' to create new remote branches)
-1
+255
 % fail on multiple head push
 pushing to ../f
 searching for changes
 abort: push creates new remote heads on branch 'a'!
 (did you forget to merge? use push -f to force)
-1
+255
 % push replacement head on existing branches
 pushing to ../f
 searching for changes
@@ -149,7 +149,7 @@
 searching for changes
 abort: push creates new remote branches: e!
 (use 'hg push --new-branch' to create new remote branches)
-1
+255
 % using --new-branch to push new named branch
 pushing to ../f
 searching for changes