mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make pre_commit also support pre-push hook
This commit is contained in:
parent
d2b11a0c50
commit
b707cbba06
10 changed files with 227 additions and 42 deletions
|
|
@ -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
|
||||
|
||||
12
pre_commit/resources/pre-push-tmpl
Executable file
12
pre_commit/resources/pre-push-tmpl
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue