--- a/hgext/states.py Sun Sep 25 12:43:00 2011 +0200
+++ b/hgext/states.py Thu Sep 22 19:18:40 2011 +0200
@@ -517,7 +517,7 @@
return 1
if off:
if st in repo._enabledstates:
- repo._enabledstates.remove(st)
+ repo.disablestate(st)
else:
ui.write_err(_('state %s already deactivated\n') %
state_name)
@@ -786,7 +786,24 @@
break
return state
-
+ def disablestate(self, state):
+ """Disable empty state.
+ Raise error.Abort if the state is not empty.
+ """
+ # the lowest is mandatory
+ if state == ST0:
+ raise error.Abort(_('could not disable %s' % state.name))
+ enabled = self._enabledstates
+ # look up for lower state that is enabled (at least published)
+ lower = max(st for st in self._enabledstates if st < state)
+ if repo.stateheads(state) != repo.stateheads(lower):
+ raise error.Abort(
+ _('could not disable non empty state %s' % state.name),
+ hint=_("You may want to use `hg %s '%sheads()'`"
+ % (lower.name, state.name))
+ )
+ else:
+ enabled.remove(state)
def stateheads(self, state):
"""Return the set of head that define the state"""