D6731: exchange: abort on pushing bookmarks pointing to secret changesets (issue6159)

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Fri Aug 16 16:26:30 EDT 2019


navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Until now, if there is a bookmark points to a changeset which is in secret
  phase, hg will push the bookmark, but not the changeset referenced by that
  bookmark. This leaves the server bookmarks in a bad state, because that
  bookmark now points to a revision that does not exist on the server. This
  patch makes hg to abort on such cases.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6731

AFFECTED FILES
  mercurial/exchange.py
  tests/test-bookmarks-pushpull.t

CHANGE DETAILS

diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -1322,3 +1322,42 @@
   abort: push failed on remote
   [255]
 #endif
+
+-- test for stop pushing bookmarks pointing to secret changesets
+
+Set up a "remote" repo
+  $ hg init issue6159remote
+  $ cd issue6159remote
+  $ echo a > a
+  $ hg add a
+  $ hg commit -m_
+  $ hg bookmark foo
+  $ cd ..
+
+Clone a local repo
+  $ hg clone -q issue6159remote issue6159local
+  $ cd issue6159local
+  $ hg up -qr foo
+  $ echo b > b
+
+Move the bookmark "foo" to point at a secret changeset
+  $ hg commit -qAm_
+  $ hg phase -s -f
+
+Pushing the bookmark "foo" now fails as it contains a secret changeset
+#if b2-pushkey
+  $ hg push -r foo
+  pushing to $TESTTMP/issue6159remote
+  searching for changes
+  no changes found (ignored 1 secret changesets)
+  abort: bookmark foo points to a secret changeset
+  [255]
+#endif
+#if b2-binary
+  $ hg push -r foo
+  pushing to $TESTTMP/issue6159remote
+  searching for changes
+  no changes found (ignored 1 secret changesets)
+  abort: bookmark foo points to a secret changeset
+  [255]
+#endif
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1034,6 +1034,15 @@
         return 'delete'
     return 'update'
 
+def _abortonsecretctx(pushop, node, b):
+    """abort if a given bookmark points to a secret changeset"""
+    if not node:
+        return False
+    ctx = pushop.repo[node]
+    if ctx.phase() == phases.secret:
+        raise error.Abort(_('bookmark %s points to a secret changeset') % b)
+    return False
+
 def _pushb2bookmarkspart(pushop, bundler):
     pushop.stepsdone.add('bookmarks')
     if not pushop.outbookmarks:
@@ -1042,6 +1051,7 @@
     allactions = []
     data = []
     for book, old, new in pushop.outbookmarks:
+        _abortonsecretctx(pushop, new, book)
         new = bin(new)
         data.append((book, new))
         allactions.append((book, _bmaction(old, new)))
@@ -1070,6 +1080,7 @@
         assert False
 
     for book, old, new in pushop.outbookmarks:
+        _abortonsecretctx(pushop, new, book)
         part = bundler.newpart('pushkey')
         part.addparam('namespace', enc('bookmarks'))
         part.addparam('key', enc(book))



To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list