Make pre_commit also support pre-push hook

This commit is contained in:
dongweiming 2015-01-11 22:40:35 +08:00 committed by Anthony Sottile
parent d2b11a0c50
commit b707cbba06
10 changed files with 227 additions and 42 deletions

View file

@ -7,6 +7,7 @@ HERE=`pwd`
popd > /dev/null
retv=0
args=""
ENV_PYTHON='{sys_executable}'
@ -23,29 +24,30 @@ if ((
(ENV_PYTHON_RETV != 0) &&
(PYTHON_RETV != 0)
)); then
echo '`pre-commit` not found. Did you forget to activate your virtualenv?'
echo '`{hook_type}` not found. Did you forget to activate your virtualenv?'
exit 1
fi
# Run the legacy pre-commit if it exists
if [ -x "$HERE"/pre-commit.legacy ]; then
"$HERE"/pre-commit.legacy
if [ -x "$HERE"/{hook_type}.legacy ]; then
"$HERE"/{hook_type}.legacy
if [ $? -ne 0 ]; then
retv=1
fi
fi
{pre_push}
# Run pre-commit
if ((WHICH_RETV == 0)); then
pre-commit
pre-commit $args
PRE_COMMIT_RETV=$?
elif ((ENV_PYTHON_RETV == 0)); then
"$ENV_PYTHON" -m pre_commit.main
"$ENV_PYTHON" -m pre_commit.main $args
PRE_COMMIT_RETV=$?
else
python -m pre_commit.main
python -m pre_commit.main $args
PRE_COMMIT_RETV=$?
fi

View file

@ -0,0 +1,12 @@
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" != $z40 ]; then
if [ "$remote_sha" = $z40 ];
then
args="run --all-files"
else
args="run --origin $local_sha --source $remote_sha"
fi
fi
done