mirror of
https://github.com/quay/quay.git
synced 2026-01-27 18:42:52 +03:00
* dev: Add pre-commit script to run black (PROJQUAY-4039) Automatically formats python files before commit * Add makefile target to install hook * Update instructions for installing pre-commit hook
26 lines
431 B
Bash
Executable File
26 lines
431 B
Bash
Executable File
#!/bin/bash
|
|
|
|
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
|
|
|
|
FILES=$(git diff-index --name-only $against | grep ".*.py" | xargs)
|
|
|
|
if [ -z "$FILES" ]; then
|
|
# No python files, skip
|
|
exit 0
|
|
fi
|
|
|
|
if black --line-length=100 --target-version=py38 $FILES; then
|
|
git add $FILES
|
|
exit 0
|
|
fi
|
|
|
|
exit 1
|
|
|
|
|