hghooks: add hook to prevent try_task_config.json from landing on non-try trees (
bug 1380357), r?gps
MozReview-Commit-ID: 67RzJtZrfYy
new file mode 100644
--- /dev/null
+++ b/hghooks/mozhghooks/prevent_try_config.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+TRY_CONFIG_FOUND = """
+You are trying to commit the temporary 'try_task_config.json' file
+on a non-try branch. Either make sure you are pushing to try or
+remove the file and push again.
+"""
+
+
+def print_banner(ui, level, message):
+ width = max(len(l) for l in message.splitlines())
+ banner = [
+ ' {} '.format(level.upper()).center(width, '*'),
+ message.strip(),
+ '*' * width,
+ ]
+ ui.write('\n' + '\n'.join(banner) + '\n\n')
+
+
+def hook(ui, repo, node, source=None, **kwargs):
+ if source in ('pull', 'strip'):
+ return 0
+
+ for rev in repo.changelog.revs(repo[node].rev()):
+ ctx = repo[rev]
+ if 'try_task_config.json' in ctx.files():
+ print_banner(ui, 'error', TRY_CONFIG_FOUND)
+ return 1
+
+ return 0
new file mode 100644
--- /dev/null
+++ b/hghooks/tests/test-prevent-try-config.t
@@ -0,0 +1,71 @@
+ $ hg init server
+ $ cat > server/.hg/hgrc << EOF
+ > [hooks]
+ > pretxnchangegroup.prevent_try_config = python:mozhghooks.prevent_try_config.hook
+ > EOF
+
+ $ hg -q clone server client
+ $ cd client
+
+Regular file changes work
+
+ $ touch file0
+ $ 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
+
+Can't push try_task_config.json
+
+ $ echo "config" > try_task_config.json
+ $ hg -q commit -A -m 'add nsprpub/file'
+
+ $ 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
+
+ ***************************** ERROR ******************************
+ You are trying to commit the temporary 'try_task_config.json' file
+ on a non-try branch. Either make sure you are pushing to try or
+ remove the file and push again.
+ ******************************************************************
+
+ transaction abort!
+ rollback completed
+ abort: pretxnchangegroup.prevent_try_config hook failed
+ [255]
+
+Multiple changesets handled properly
+
+ $ touch file1
+ $ hg -q commit -A -m 'add file1'
+ $ touch file2
+ $ hg -q commit -A -m 'add file2'
+
+ $ hg push
+ pushing to $TESTTMP/server
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 3 changesets with 3 changes to 3 files
+
+ ***************************** ERROR ******************************
+ You are trying to commit the temporary 'try_task_config.json' file
+ on a non-try branch. Either make sure you are pushing to try or
+ remove the file and push again.
+ ******************************************************************
+
+ transaction abort!
+ rollback completed
+ abort: pretxnchangegroup.prevent_try_config hook failed
+ [255]