obsolete: refuse to push unstable changeset without -f
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 24 Apr 2012 16:30:58 +0200
changeset 217 786eb34d93ea
parent 216 9400e234b3d7
child 218 ace5608350b6
obsolete: refuse to push unstable changeset without -f We do not alter phase of suspended and unstable changeset anymore. But push refuse to push them without force. The extinct part of the history stay secret for simplicity shake.
docs/tutorials/tutorial.t
hgext/obsolete.py
tests/test-obsolete.t
--- a/docs/tutorials/tutorial.t	Tue Apr 24 15:57:48 2012 +0200
+++ b/docs/tutorials/tutorial.t	Tue Apr 24 16:30:58 2012 +0200
@@ -495,26 +495,25 @@
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   1 new unstables changesets
   $ hg log
-  9ac5d0e790a2 (secret): animals
+  9ac5d0e790a2 (draft): animals
   ffa278c50818 (draft): bathroom stuff
-  8a79ae8b029e (secret): bathroom stuff
+  8a79ae8b029e (draft): bathroom stuff
   a2fccc2e7b08 (public): SPAM SPAM
   387187ad9bd9 (public): adding fruit
   dfd3a2d7691e (public): adding condiment
   9ca060c80d74 (public): SPAM
   7e82d3f3c2cb (public): Monthy Python Shopping list
 
-# XXX Changeset have turned secret because of current implementation of mutable.
 
 The new changeset "animal" is based one an old changeset of "bathroom". You can
 see both version showing up the log.
 
   $ hg glog
-  o  9ac5d0e790a2 (secret): animals
+  o  9ac5d0e790a2 (draft): animals
   |
   | @  ffa278c50818 (draft): bathroom stuff
   | |
-  o |  8a79ae8b029e (secret): bathroom stuff
+  o |  8a79ae8b029e (draft): bathroom stuff
   |/
   o  a2fccc2e7b08 (public): SPAM SPAM
   |
@@ -548,7 +547,7 @@
 The old version of bathroom is hidden again now.
 
   $ hg log
-  437efbcaf700 (secret): animals
+  437efbcaf700 (draft): animals
   ffa278c50818 (draft): bathroom stuff
   a2fccc2e7b08 (public): SPAM SPAM
   387187ad9bd9 (public): adding fruit
@@ -556,11 +555,6 @@
   9ca060c80d74 (public): SPAM
   7e82d3f3c2cb (public): Monthy Python Shopping list
 
-XXX remove me when fixed
-restore a proper phase for animals
-
-  $ hg ph -dv 437efbcaf700
-  phase changed for 1 changesets
 
 We can push this evolution to remote
 
@@ -623,8 +617,8 @@
 is neither dead or obsolete.  My repository is in an unstable state again.
 
   $ hg log
-  ae45c0c3092a (secret): SPAM SPAM SPAM
-  437efbcaf700 (secret): animals
+  ae45c0c3092a (draft): SPAM SPAM SPAM
+  437efbcaf700 (draft): animals
   ffa278c50818 (draft): bathroom stuff
   a2fccc2e7b08 (public): SPAM SPAM
   387187ad9bd9 (public): adding fruit
@@ -633,12 +627,12 @@
   7e82d3f3c2cb (public): Monthy Python Shopping list
 
   $ hg log -r 'unstable()'
-  ae45c0c3092a (secret): SPAM SPAM SPAM
+  ae45c0c3092a (draft): SPAM SPAM SPAM
 
   $ hg log -G
-  o  ae45c0c3092a (secret): SPAM SPAM SPAM
+  o  ae45c0c3092a (draft): SPAM SPAM SPAM
   |
-  o  437efbcaf700 (secret): animals
+  o  437efbcaf700 (draft): animals
   |
   @  ffa278c50818 (draft): bathroom stuff
   |
--- a/hgext/obsolete.py	Tue Apr 24 15:57:48 2012 +0200
+++ b/hgext/obsolete.py	Tue Apr 24 16:30:58 2012 +0200
@@ -304,6 +304,22 @@
     outgoing.excluded.orig = orig
     return outgoing
 
+def wrapcheckheads(orig, repo, remote, outgoing, *args, **kwargs):
+    """wrap mercurial.discovery.checkheads to prevent unstability to be pushed"""
+    for h in outgoing.missingheads:
+        # checking heads only is enought because any thing base on obsolete
+        # changeset is either obsolete or unstable.
+        ctx =  repo[h]
+        hint = _("use 'hg stabilize' to get a stable history (or --force to proceed)")
+        if ctx.unstable():
+            raise util.Abort(_("Trying to push unstable changeset: %s!") % ctx,
+                             hint=hint)
+        if ctx.obsolete():
+            raise util.Abort(_("Trying to push obsolete changeset: %s!") % ctx,
+                             hint=hint)
+    return orig(repo, remote, outgoing, *args, **kwargs)
+
+
 ### New commands
 #############################
 
@@ -332,6 +348,7 @@
     extensions.wrapcommand(commands.table, "update", wrapmayobsoletewc)
     extensions.wrapcommand(commands.table, "pull", wrapmayobsoletewc)
     extensions.wrapfunction(discovery, 'findcommonoutgoing', wrapfindcommonoutgoing)
+    extensions.wrapfunction(discovery, 'checkheads', wrapcheckheads)
 
 ### serialisation
 #############################
@@ -650,12 +667,8 @@
 
 
     repo.__class__ = obsoletingrepo
-    if repo.ui.configbool('obsolete', 'secret-unstable', True):
-        symbol = 'obsolete()'
-    else:
-        symbol = 'extinct()'
 
-    expobs = [c.node() for c in repo.set('%s - secret()' % symbol)]
+    expobs = [c.node() for c in repo.set('extinct() - secret()')]
     if expobs: # do not lock in nothing move. locking for peanut make hgview reload on any command
         lock = repo.lock()
         try:
--- a/tests/test-obsolete.t	Tue Apr 24 15:57:48 2012 +0200
+++ b/tests/test-obsolete.t	Tue Apr 24 16:30:58 2012 +0200
@@ -4,8 +4,6 @@
   > allow_push = *
   > [phases]
   > publish=False
-  > [obsolete]
-  > secret-unstable=no
   > [alias]
   > odiff=diff --rev 'limit(obsparents(.),1)' --rev .
   > [extensions]
@@ -117,7 +115,13 @@
 
   $ hg init ../other-new
   $ hg phase --draft 'secret() - extinct()' # until we fix exclusion
-  $ hg push --traceback ../other-new
+  $ hg push ../other-new
+  pushing to ../other-new
+  searching for changes
+  abort: Trying to push unstable changeset: a7a6f2b5d8a5!
+  (use 'hg stabilize' to get a stable history (or --force to proceed))
+  [255]
+  $ hg push -f ../other-new
   pushing to ../other-new
   searching for changes
   adding changesets
@@ -163,7 +167,13 @@
   $ qlog -r 'obsolete()'
   3
   - 0d3f46688ccc
-  $ hg push ../other-new -f # XXX should not have to use -f
+  $ hg push ../other-new
+  pushing to ../other-new
+  searching for changes
+  abort: Trying to push unstable changeset: 95de7fc6918d!
+  (use 'hg stabilize' to get a stable history (or --force to proceed))
+  [255]
+  $ hg push ../other-new -f # use f because there is unstability
   pushing to ../other-new
   searching for changes
   adding changesets
@@ -228,6 +238,12 @@
   $ hg push ../other-old
   pushing to ../other-old
   searching for changes
+  abort: Trying to push unstable changeset: 909a0fb57e5d!
+  (use 'hg stabilize' to get a stable history (or --force to proceed))
+  [255]
+  $ hg push -f ../other-old
+  pushing to ../other-old
+  searching for changes
   adding changesets
   adding manifests
   adding file changes