3 ms·
This is cool but why do we need it if Mercurial already supports pre-commit hooks? For example we have this for refreshing redmine: #!/bin/sh PROJ=""
by EGreg 12y ago
This is cool but why do we need it if Mercurial already supports pre-commit hooks?
For example we have this for refreshing redmine:
#!/bin/sh
PROJ=""
while [ $# -gt 0 ] ; do
case $1 in
--project)
shift
PROJ="&id=$1"
shift
;;
esac
done
echo $"Refreshing Redmine"
curl -s -o /dev/null "http://issues.qbixstaging.com/sys/fetch_changesets?key=jI$
and here is our PHP syntax check:
#!/bin/sh
### Configuration
HGBIN="/usr/bin/hg"
phpPath="/usr/bin/php"
tmpstyle=`/bin/mktemp -t`
### hg log style file
cat > $tmpstyle << EOF
changeset = "{files}\n"
file = "{file}\n"
EOF
### PHP syntax check
for f in `$HGBIN log -r $HG_NODE:tip --style $tmpstyle | grep -E "\.php[3-5]?$" | sort | uniq` ; do
res=`$HGBIN cat -r tip $f | $phpPath -l -d display_errors=1 -d error_reporting=4`
if [ $? -ne 0 ] ; then
echo $f 1>&2
echo $res 1>&2
exit 1
fi
done
rm $tmpstyle
finally here is one for JS:
#!/bin/sh
### Configuration
HGBIN="/usr/bin/hg"
jshPath="/usr/local/bin/jshint"
tmpstyle=`/bin/mktemp -t`
### hg log style file
cat > $tmpstyle << EOF
changeset = "{files}\n"
file = "{file}\n"
EOF
### JS syntax check
for f in `$HGBIN log -r $HG_NODE:tip --style $tmpstyle | grep -E "\.js$" | sort | uniq` ; do
res=`$HGBIN cat -r tip $f | $jshPath --config /projects/.jshintrc --verbose - | grep "(E"`
st=$?
if [ $st -eq 0 ] ; then
echo $f 1>&2
echo $res 1>&2
exit 1
fi
if [ $st -gt 1 ] ; then
exit 1
fi
done
rm $tmpstyle
- struys 12y agoWe had something similar before building pre-commit and it served us well for many years. The issue is it grew to be a really long bash file with a lot of copy and pasted code (for lots of different hooks). We built pre-commit to reduce the code duplication and allow all developers to install new hooks that are not installed on the system. We also handle interesting cases like dealing with merge conflicts (see "pre-commit during merges" http://pre-commit.com/#advanced http://pre-commit.com/#advanced). aside: It would be cool to support mercurial in the future :D