diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd2a9bf2f52643ac2de4431a52022792bdaaac5d..2af73f120b4f10236b39fa428e0bced0e9451560 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,11 @@ repos: entry: git diff --check --cached -- ':!*.md' ':!*.pandoc' ':!*.asc' ':!*.dat' ':!*.ts' language: system stages: [commit, manual] + - id: file-extensions + name: Check file extensions + entry: scripts/hooks/pre-commit-file-extensions.sh + language: system + stages: [commit, manual] - id: git-lfs name: Check git lfs files entry: scripts/hooks/pre-commit-git-lfs.sh diff --git a/scripts/hooks/pre-commit-file-extensions.sh b/scripts/hooks/pre-commit-file-extensions.sh new file mode 100755 index 0000000000000000000000000000000000000000..1b6c6d9933bc040387e208c49d77f1727a788ef8 --- /dev/null +++ b/scripts/hooks/pre-commit-file-extensions.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# set -e + +# Check for uppercase letters in filename extensions +pattern=".*\.\w*([A-Z]+)\w*$" +files=$(git diff --cached --find-copies --find-renames --name-only --diff-filter=ACMRTXBU | + grep -E "$pattern" ) + +if [[ -n $files ]]; +then + echo "Attention!" + echo "----------" + echo "Found files that contain capital letters in the file extension." + echo "Please rename the following files and commit again:" + + while read -r file; do + echo -e '\E[0;32m'"$file"'\033[0m' + done <<< "$files" + # Abort commit + exit 1 +fi + +exit 0 diff --git a/scripts/hooks/pre-commit-git-lfs.sh b/scripts/hooks/pre-commit-git-lfs.sh index 4b71c7d77f8f7f495d802628774bb3e435625981..88caf5f95bcd10d7d6661b9365c9b81fc0938628 100755 --- a/scripts/hooks/pre-commit-git-lfs.sh +++ b/scripts/hooks/pre-commit-git-lfs.sh @@ -3,17 +3,28 @@ set -e BINARY_FILES="" -CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) -LFS_FILES=$(echo $CHANGED_FILES | xargs -I{lin} git check-attr filter "{lin}" | grep 'filter: lfs$' | sed -e 's/: filter: lfs//') +LFS_FILES="" +CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTXBU) -for FILE in $LFS_FILES; do - SOFT_SHA=$(git hash-object -w $FILE) - RAW_SHA=$(git hash-object -w --no-filters $FILE) +while read -r FILE; do + LFS_FILE=$(git check-attr filter "$FILE" | grep 'filter: lfs$' | sed -e 's/: filter: lfs//') + if [ ! -z "$LFS_FILE" ]; then + LFS_FILES="$LFS_FILES $LFS_FILE" + fi +done <<< "$CHANGED_FILES" + +if [ -z "$LFS_FILES" ]; then + exit 0 +fi + +while read -r FILE; do + SOFT_SHA=$(git hash-object -w "$FILE") + RAW_SHA=$(git hash-object -w --no-filters "$FILE") if [ $SOFT_SHA == $RAW_SHA ]; then BINARY_FILES="$FILE\n$BINARY_FILES" fi -done +done <<< "$LFS_FILES" if [[ -n "$BINARY_FILES" ]]; then echo "Attention!"