test-pushvars: add a test about Python hook

Summary:
The Python hook got "kwargs" without "HG_" prefix. Add an explicit test for it.

Also remove unnecessary configs and change the shell to bash, since we don't
run tests using vanilla "sh".

check-code is updated so it no longer complains about the use of `bash`.

Reviewed By: markbt

Differential Revision: D9561962

fbshipit-source-id: 76a190dde1b0aeb0032a65c173ce6368a28e8cf6
This commit is contained in:
Jun Wu 2018-09-11 17:53:58 -07:00 committed by Facebook Github Bot
parent 02ea73b1d5
commit 8a42f77192
2 changed files with 26 additions and 8 deletions

View File

@ -146,7 +146,6 @@ testpats = [
(r"(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w", "use egrep for extended grep syntax"),
(r"(^|\|\s*)e?grep .*\\S", "don't use \\S in regular expression"),
(r"(?<!!)/bin/", "don't use explicit paths for tools"),
(r"#!.*/bash", "don't use bash in shebang, use sh"),
(r"[^\n]\Z", "no trailing newline"),
(r"^source\b", "don't use 'source', use '.'"),
(r"touch -d", "don't use 'touch -d', use 'touch -t' instead"),

View File

@ -2,19 +2,14 @@
Setup
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
$ export PYTHONPATH
$ cat > $TESTTMP/pretxnchangegroup.sh << EOF
> #!/bin/sh
> #!/bin/bash
> env | egrep "^HG_USERVAR_(DEBUG|BYPASS_REVIEW)" | sort
> exit 0
> EOF
$ cat >> $HGRCPATH << EOF
> [hooks]
> pretxnchangegroup = sh $TESTTMP/pretxnchangegroup.sh
> [experimental]
> bundle2-exp = true
> pretxnchangegroup = bash $TESTTMP/pretxnchangegroup.sh
> EOF
$ hg init repo
@ -71,3 +66,27 @@ Test pushing bad vars
searching for changes
abort: unable to parse variable 'DEBUG', should follow 'KEY=VALUE' or 'KEY=' format
[255]
Test Python hooks
$ cat >> $TESTTMP/pyhook.py << EOF
> def hook(ui, repo, hooktype, **kwargs):
> for k, v in sorted(kwargs.items()):
> if "USERVAR" in k:
> ui.write("Got pushvar: %s=%s\n" % (k, v))
> EOF
$ cat >> $HGRCPATH << EOF
> [hooks]
> pretxnchangegroup.pyhook = python:$TESTTMP/pyhook.py:hook
> EOF
$ hg push --pushvars "A=1" --pushvars "B=2"
pushing to $TESTTMP/repo
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
Got pushvar: USERVAR_A=1
Got pushvar: USERVAR_B=2