Create a pre-commit hook which is copied on installation

Allow propogating specific files to format for black

Update build messages for black

update hook

Update hook further, add related doc
This commit is contained in:
Grant Lanham 2024-08-24 00:25:58 -04:00
parent 4f7dd05d99
commit bce9669d74
4 changed files with 44 additions and 3 deletions

12
.githooks/pre-commit Executable file
View file

@ -0,0 +1,12 @@
#!/bin/sh
if [ "$SEARXNG_PRECOMMIT" = "true" ]; then
# inspired from: https://prettier.io/docs/en/precommit.html#option-4-shell-script
staged_files=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
python_files=$(echo "$staged_files" | grep '\.py$')
# Only attempt to run the formatter if Python files were changes
if [ -n "$python_files" ]; then
echo "$python_files" | xargs ./manage format.python
echo "$python_files" | xargs git add
fi
fi