[PATCH] phase: when phase cannot be reduced, hint at --force and return 1 (BC)
Patrick Mezard
patrick at mezard.eu
Wed Feb 8 19:08:49 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1328727652 -3600
# Node ID 964f1038f52cdfa0f3aec5199d7645ac0f095307
# Parent e1d8218d733bb318605308fa8c6f261f49d0c163
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 @@
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 @@
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 @@
|
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]
More information about the Mercurial-devel
mailing list