From 2d23a00c19211601958e221274ece2df8bf111bb Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sun, 27 Aug 2023 11:51:13 +0300 Subject: [PATCH] Make python pre-commit hook fail if it would reformat Currently, when I run `git commit` with a staged file that would be reformatted by the pre-commit hook, the hook will reformat the file but the the commit succeed with the unforamtted staged files. I'd like to make the pre-commit hook fail if it would reformat the file, so that I can fix the formatting and then commit. --- lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lint.sh b/lint.sh index 7bba96e1..7ae0fddb 100755 --- a/lint.sh +++ b/lint.sh @@ -16,6 +16,6 @@ fi EXCLUDE_RE='.venv|venv|build|granulate_utils/generated' python3 -m isort --settings-path .isort.cfg $check_arg --skip granulate_utils/generated --skip venv --skip .venv --skip build . -python3 -m black --line-length 120 $check_arg --exclude $EXCLUDE_RE . +python3 -m black --check --diff --color --line-length 120 $check_arg --exclude $EXCLUDE_RE . python3 -m flake8 --config .flake8 --exclude $(echo $EXCLUDE_RE | tr '|' ',') . python3 -m mypy --exclude $EXCLUDE_RE .