# HG changeset patch # User Benoit Boissinot # Date 2010-07-15 12:41:22 # Node ID 6381fa7bfa53a7e108f3db4c71df30e40cfac856 # Parent 7ecf4a082c5fadb048e3df3a80dedc118509bc72 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 diff --git a/mercurial/discovery.py b/mercurial/discovery.py --- a/mercurial/discovery.py +++ b/mercurial/discovery.py @@ -252,18 +252,16 @@ def prepush(repo, remote, force, revs, n 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 @@ def prepush(repo, remote, force, revs, n 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. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -23,6 +23,8 @@ def dispatch(args): 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 @@ def _runcatch(ui, args): 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] diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -32,6 +32,9 @@ class CommandError(Exception): 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' diff --git a/tests/test-push-warn.out b/tests/test-push-warn.out --- a/tests/test-push-warn.out +++ b/tests/test-push-warn.out @@ -37,7 +37,7 @@ 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 no changes found @@ -46,12 +46,12 @@ 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 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 @@ 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 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 @@ pushing to ../f 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