Comments
Patch
new file mode 100644
@@ -0,0 +1,25 @@
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+# This hook (meant to be installed as a pretxnchangegroup hook)
+# will reject changesets containing either a .hgsub or .hgsubtate
+# file. These files define subrepos. Preventing the existence of
+# these files effectively disables the subrepo feature.
+#
+# This hook can be installed by adding the following in your hgrc:
+#
+# [hooks]
+# pretxnchangegroup.prevent_subrepos = python:/path/to/prevent-subrepos.py:hook
+
+def hook(ui, repo, node, hooktype, **kwargs):
+ for rev in repo.changelog.revs(repo[node].rev()):
+ ctx = repo[rev]
+
+ if '.hgsub' not in ctx and '.hgsubstate' not in ctx:
+ return 0
+
+ ui.write('error: subrepos are not allowed in this repository\n')
+ ui.write('remove the .hgsub and/or .hgsubstate file\n')
+ return 1
new file mode 100644
@@ -0,0 +1,44 @@
+ $ hg init hgsub
+ $ cd hgsub
+ $ echo sub0 > foo
+ $ hg -q commit -A -m 'initial sub'
+ $ cd ..
+
+ $ hg init server
+ $ cat > server/.hg/hgrc << EOF
+ > [hooks]
+ > pretxnchangegroup.subrepo = python:$TESTDIR/../contrib/prevent-subrepos.py:hook
+ > EOF
+ $ hg -q clone --pull server client
+ $ cd client
+
+ $ echo 0 > foo
+ $ hg -q commit -A -m initial
+ $ hg -q push
+
+Add a subrepo
+
+ $ cat > .hgsub << EOF
+ > hgsub = ../hgsub
+ > EOF
+
+ $ hg add .hgsub
+ $ hg commit -m 'add hgsub'
+
+Hook rejects push
+
+ $ hg push
+ pushing to $TESTTMP/server
+ pushing subrepo hgsub to $TESTTMP/hgsub
+ no changes found
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 2 changes to 2 files
+ error: subrepos are not allowed in this repository
+ remove the .hgsub and/or .hgsubstate file
+ transaction abort!
+ rollback completed
+ abort: pretxnchangegroup.subrepo hook failed
+ [255]