hghooks: add a hook that disallows pushing bookmarks (
bug 1264659); r?smacleod
The intent is to enable this on the Firefox repos to prevent accidents
related to the imminent introduction of bookmarks on the unified Firefox
repos being created in
bug 1108729.
MozReview-Commit-ID: 2IqngTJ4jGi
new file mode 100644
--- /dev/null
+++ b/hghooks/mozhghooks/prevent_bookmarks.py
@@ -0,0 +1,19 @@
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Hook that prevents bookmarks from being set.
+
+It may not prevent bookmark setting via all scenarios. The main aim is to
+prevent bookmark pushing via the wire protocol.
+"""
+
+def hook(ui, repo, hooktype, namespace, key, old, new, source=None, **kwargs):
+ if source in ('pull', 'strip'):
+ return 0
+
+ if namespace != 'bookmarks':
+ return 0
+
+ ui.write('bookmarks are disabled on this repository; '
+ 'refusing to accept modification to "%s"\n' % key)
+ return 1
new file mode 100644
--- /dev/null
+++ b/hghooks/tests/test-prevent-bookmarks.t
@@ -0,0 +1,42 @@
+ $ hg init server
+ $ cd server
+ $ cat >> .hg/hgrc << EOF
+ > [hooks]
+ > prepushkey.prevent_bookmarks = python:mozhghooks.prevent_bookmarks.hook
+ > EOF
+ $ cd ..
+
+ $ hg clone server client
+ updating to branch default
+ 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd client
+ $ touch foo
+ $ hg -q commit -A -m initial
+ $ hg push
+ pushing to $TESTTMP/server
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+
+Pushing a bookmark is not allowed
+
+ $ hg book book1
+ $ hg push -B book1
+ pushing to $TESTTMP/server
+ searching for changes
+ no changes found
+ bookmarks are disabled on this repository; refusing to accept modification to "book1"
+ pushkey-abort: prepushkey.prevent_bookmarks hook failed
+ abort: exporting bookmark book1 failed!
+ [255]
+
+Pulling a bookmark on the server is allowed
+
+ $ cd ../server
+ $ hg pull ../client
+ pulling from ../client
+ searching for changes
+ no changes found
+ adding remote bookmark book1