Skip to content
Snippets Groups Projects
Commit bfda1cb4 authored by Lars Bilke's avatar Lars Bilke
Browse files

[hook] Added file extension check, fixed lfs check.

parent 97bb7c8d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#!/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
......@@ -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!"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment