#!/bin/bash # Set up with `pushd .git/hooks; ln -s ../../hooks/pre-commit pre-commit; popd` set -eux if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD else # Initial commit: diff against an empty tree object against=$(git hash-object -t tree /dev/null) fi # cat always has error code 0 # ignore deleted files (can't be formatted) filenames=$(git diff --cached --name-only --diff-filter=d $against | grep '\.py$' | cat) # If changed files include scrapscript.py, run tests if echo $filenames | grep scrapscript then python3 ./scrapscript_tests.py fi # If there are any other changed Python files, make sure they lint if [ -n "$filenames" ] then ruff format --check $filenames ruff check $filenames mypy --strict $filenames fi