# HG changeset patch # User Patrick Mezard # Date 2012-02-08 19:00:52 # Node ID 8dc573a9c5e513bd859b2f65d461b039aa505d1e # Parent b8be450638f6a3b6975be551a7d50394b8dfae71 phase: when phase cannot be reduced, hint at --force and return 1 (BC) Before, trying to change the phase of a "public" node to "draft" would result in: $ hg phase --draft . no phases changed [0] With this patch: $ hg phase --draft . cannot move 1 changesets to a more permissive phase, use --force no phases changed [1] On partial failures, the exit status is now 1 instead of 0 and the number of changed nodes is displayed while it was only with --verbose. It seems useful to tell the user that despite the apparent failure, something changed. $ hg phase --draft '5 or 7' cannot move 1 changesets to a more permissive phase, use --force phase changed for 1 changesets [1] diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -4210,7 +4210,8 @@ def phase(ui, repo, *revs, **opts): public < draft < secret - Return 0 on success, 1 if no phases were changed. + Return 0 on success, 1 if no phases were changed or some could not + be changed. """ # search for a unique phase argument targetphase = None @@ -4252,8 +4253,18 @@ def phase(ui, repo, *revs, **opts): changes = 0 newdata = repo._phaserev changes = sum(o != newdata[i] for i, o in enumerate(olddata)) + rejected = [n for n in nodes + if newdata[repo[n].rev()] < targetphase] + if rejected: + ui.warn(_('cannot move %i changesets to a more permissive ' + 'phase, use --force\n') % len(rejected)) + ret = 1 if changes: - ui.note(_('phase change for %i changesets\n') % changes) + msg = _('phase changed for %i changesets\n') % changes + if ret: + ui.status(msg) + else: + ui.note(msg) else: ui.warn(_('no phases changed\n')) ret = 1 diff --git a/tests/test-phases.t b/tests/test-phases.t --- a/tests/test-phases.t +++ b/tests/test-phases.t @@ -402,3 +402,34 @@ move changeset forward and backward | o 0 public A +test partial failure + + $ hg phase --public 7 + $ hg phase --draft '5 or 7' + cannot move 1 changesets to a more permissive phase, use --force + phase changed for 1 changesets + [1] + $ hg log -G --template "{rev} {phase} {desc}\n" + @ 7 public merge B' and E + |\ + | o 6 public B' + | | + +---o 5 draft H + | | + o | 4 public E + | | + o | 3 public D + | | + o | 2 public C + |/ + o 1 public B + | + o 0 public A + + +test complete failure + + $ hg phase --draft 7 + cannot move 1 changesets to a more permissive phase, use --force + no phases changed + [1]