# HG changeset patch # User Pierre-Yves David # Date 1315864026 -7200 # Node ID f47a5f990eb2b0ebbda4b1f671a2e6e2b9a6fcc9 # Parent bd33e749dfccee413e001c8887a81f9601a225be [states] add rebase support. diff -r bd33e749dfcc -r f47a5f990eb2 hgext/states.py --- a/hgext/states.py Mon Sep 12 19:35:50 2011 +0200 +++ b/hgext/states.py Mon Sep 12 23:47:06 2011 +0200 @@ -247,6 +247,13 @@ - add ``()`` directives that match all node in a state. +Other extensions +................ + +:Rebase: can't rewrite unpublished changeset. + + + Implementation ============== @@ -634,6 +641,22 @@ h = repo.stateheads(st) return wireproto.encodelist(h) + "\n" +# Other extension support +######################### + +def wraprebasebuildstate(orig, repo, *args, **kwargs): + result = orig(repo, *args, **kwargs) + if result is not None: + revs = result[2] + base = repo.changelog.node(min(result[2])) + state = repo.nodestate(base) + if not state.properties & _MUTABLE: + raise util.Abort(_('can not rebase published changeset %s') + % node.short(base), + hint=_('see `hg help --extension states` for details')) + return result + + def uisetup(ui): """ * patch stuff for the _NOSHARE property @@ -656,6 +679,12 @@ for state in STATES: if state.trackheads: revset.symbols[state.headssymbol] = state._revsetheads + try: + rebase = extensions.find('rebase') + if rebase: + extensions.wrapfunction(rebase, 'buildstate', wraprebasebuildstate) + except KeyError: + pass # rebase not found diff -r bd33e749dfcc -r f47a5f990eb2 tests/test-published.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-published.t Mon Sep 12 23:47:06 2011 +0200 @@ -0,0 +1,46 @@ + + $ cat >> $HGRCPATH < [web] + > push_ssl = false + > allow_push = * + > [extensions] + > hgext.rebase= + > EOF + $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH + + +test you can't rebase published changeset + + $ hg init local + $ cd local + $ echo "celestine" > babar + $ hg add babar + $ hg ci -m "add babar" + $ echo "la veille dame" > babar + $ hg ci -m "add dame" + $ hg log --template='{rev}:{node|short}: {state}\n' + 1:710fe444b3b0: published + 0:5caa672bac26: published + $ hg up 0 -q + $ echo "Rataxes" > rhino + $ hg add rhino + $ hg ci -m "add rhino" + created new head + $ hg up 1 -q + $ hg rebase + abort: can not rebase published changeset 710fe444b3b0 + (see `hg help --extension states` for details) + [255] + +test you still can rebase other one + + $ hg published 1 2 + $ hg states draft + $ echo "flore" > babar + $ hg ci -m "add daughter" + $ hg rebase --dest 2 + abort: can not rebase published changeset 710fe444b3b0 + (see `hg help --extension states` for details) + [255] + $ hg rebase --dest 2 -s 3 + saved backup bundle to $TESTTMP/local/.hg/strip-backup/b7f6698b7ad7-backup.hg