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

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Thu Aug 22 08:25:10 EDT 2019


navaneeth.suresh updated this revision to Diff 16291.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6731?vs=16267&id=16291

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6731/new/

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
@@ -1345,38 +1345,27 @@
   $ hg log -r . --template '{node}'
   cf489fd8a374cab73c2dc19e899bde6fe3a43f8f (no-eol)
 
+Create a bookmark that points to a non-secret changeset
+  $ hg bookmark bar
+  $ echo c > c
+  $ hg ci -Am_
+  adding c
 
 Pushing the bookmark "foo" now fails as it contains a secret changeset
 #if b2-pushkey
-  $ hg push -r foo
+  $ hg push
   pushing to $TESTTMP/issue6159remote
   searching for changes
-  no changes found (ignored 1 secret changesets)
-  abort: updating bookmark foo failed!
+  no changes found (ignored 2 secret changesets)
+  abort: cannot push bookmark foo as it points to a secret changeset
   [255]
 #endif
 
 #if b2-binary
-  $ hg push -r foo
+  $ hg push
   pushing to $TESTTMP/issue6159remote
   searching for changes
-  no changes found (ignored 1 secret changesets)
-  updating bookmark foo
-  [1]
+  no changes found (ignored 2 secret changesets)
+  abort: cannot push bookmark foo as it points to a secret changeset
+  [255]
 #endif
-
-Now the "remote" repo contains a bookmark pointing to a nonexistent revision
-$ cd ../issue6159remote
-#if b2-pushkey
-  $ hg bookmark
-   * foo                       1:cf489fd8a374
-  $ hg log -r cf489fd8a374
-  1:cf489fd8a374 _ (no-eol)
-#endif
-
-#if b2-binary
-  $ hg bookmark
-   * foo                       1:cf489fd8a374
-  $ hg log -r cf489fd8a374
-  1:cf489fd8a374 _ (no-eol)
-#endif
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1034,6 +1034,12 @@
         return 'delete'
     return 'update'
 
+def _abortonsecretctx(pushop, node, b):
+    """abort if a given bookmark points to a secret changeset"""
+    if node and pushop.repo[node].phase() == phases.secret:
+        raise error.Abort(_('cannot push bookmark %s as it points to a secret'
+                            ' changeset') % b)
+
 def _pushb2bookmarkspart(pushop, bundler):
     pushop.stepsdone.add('bookmarks')
     if not pushop.outbookmarks:
@@ -1042,6 +1048,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 +1077,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: pulkit, mercurial-devel


More information about the Mercurial-devel mailing list