pytorch/tools/git-pre-commit
Michael Suo bb3c3f516b make flake8 failure blocking (#15675)
Summary:
Right now it just prints whatever flake8 errors and moves forward with the commit. This is too easy to miss.

It should block the commit so that the user can fix the issue
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15675

Differential Revision: D13567821

Pulled By: suo

fbshipit-source-id: 5f0de40ddd771bad8d6848417408cffbceb03183
2019-01-02 12:52:59 -08:00

48 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
set -e
echo "Running pre-commit flake8"
FLAKE8_OUT=$(python tools/flake8_hook.py)
if [[ ${FLAKE8_OUT} ]]
then
echo "${FLAKE8_OUT}"
exit 1
fi
if [ $(which clang-tidy) ]
then
echo "Running pre-commit clang-tidy"
python tools/clang_tidy.py \
--paths torch/csrc \
--diff HEAD \
-g"-torch/csrc/distributed/Module.cpp" \
-g"-torch/csrc/jit/export.cpp" \
-g"-torch/csrc/jit/import.cpp" \
-j
else
echo "WARNING: Couldn't find clang-tidy executable."
echo " Please install it if you want local clang-tidy checks."
fi
echo "Running pre-commit clang-format"
CLANG_FORMAT_DIFF=$(python tools/clang_format.py)
if [[ ${CLANG_FORMAT_DIFF} ]]
then
echo "${CLANG_FORMAT_DIFF}"
# Prompt user to accept clang-format changes
# From: https://stackoverflow.com/a/10015707
exec < /dev/tty
while true; do
read -p "[clang-format hook] Accept changes? (Y/n) " yn
if [ "$yn" = "" ]; then
yn='Y'
fi
case $yn in
[Yy] ) python tools/clang_format.py --accept-changes; break;;
[Nn] ) exit 1;;
* ) echo "Please answer y or n.";;
esac
done
fi