From c1db879b6c36292da92d5da763062102e818d452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 26 Jun 2025 23:55:12 +0200 Subject: [PATCH] [scripts] publish 'pre-commit' hook script (#6582) https://github.com/mikf/gallery-dl/issues/6582#issuecomment-3010067010 --- scripts/pre-commit | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/pre-commit diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 00000000..d6788af4 --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,43 @@ +#!/bin/bash + +TEMP="$(mktemp --directory)" +trap 'rm -rf -- "$TEMP"' EXIT + +while IFS="" read -r FILE +do + mkdir -p -- "$TEMP/$(dirname $FILE)" + git cat-file -p ":$FILE" > "$TEMP/$FILE" +done < <(git diff --name-only --cached --diff-filter=d) + +REPO=$PWD +cd "$TEMP" + +# ----------------------------------------------------------------------------- +py 10 -m flake8 --config "$REPO/setup.cfg" . +A=$? + +# ----------------------------------------------------------------------------- +DEBUG="$(grep --recursive --line-number \ + --exclude-dir='docs' \ + --regexp='\bif [01]:' \ + --regexp='\bif [01] and ' \ + --regexp='\bif [01] or ' \ + --regexp='\band 0\b' \ + --regexp='\bor 1\b' \ + --regexp='[[:digit:]]/0\b' \ + --regexp='\bexit()' \ + --regexp='\bprint(' \ + --regexp='\._dump(' \ + . \ +)" + +if [[ "$DEBUG" ]]; then + DEBUG="$( printf %s "$DEBUG " | sed -e 's/ */\n /' )" + printf '### Debug Remains:\n%s\n' "$DEBUG" + B=1 +fi + +# ----------------------------------------------------------------------------- +if [[ "$A" > 0 || "$B" > 0 ]]; then + exit 1 +fi