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

[hooks] Added file name check.

Fixed own hooks to use the correct files passes by pre-commit.
parent 5d1aaf15
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,12 @@ repos: ...@@ -20,6 +20,12 @@ repos:
name: Check file extensions name: Check file extensions
entry: scripts/hooks/pre-commit-file-extensions.sh entry: scripts/hooks/pre-commit-file-extensions.sh
language: system language: system
files: '.*\.cpp'
stages: [commit, manual]
- id: file-names
name: Check file names
entry: scripts/hooks/pre-commit-file-names.sh
language: system
stages: [commit, manual] stages: [commit, manual]
- id: git-lfs - id: git-lfs
name: Check git lfs files name: Check git lfs files
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
# Check for uppercase letters in filename extensions # Check for uppercase letters in filename extensions
pattern=".*\.\w*([A-Z]+)\w*$" pattern=".*\.\w*([A-Z]+)\w*$"
files=$(git diff --cached --find-copies --find-renames --name-only --diff-filter=ACMRTXBU | files=$(echo $@ | grep -E "$pattern")
grep -E "$pattern" )
if [[ -n $files ]]; if [[ -n $files ]];
then then
......
#!/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=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)
# Redirect output to stderr.
exec 1>&2
# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $($@ |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi
...@@ -4,27 +4,30 @@ set -e ...@@ -4,27 +4,30 @@ set -e
BINARY_FILES="" BINARY_FILES=""
LFS_FILES="" LFS_FILES=""
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTXBU)
while read -r FILE; do LFS_FILES=()
for FILE in "$@"
do
echo FILE: $FILE
LFS_FILE=$(git check-attr filter "$FILE" | grep 'filter: lfs$' | sed -e 's/: filter: lfs//') LFS_FILE=$(git check-attr filter "$FILE" | grep 'filter: lfs$' | sed -e 's/: filter: lfs//')
if [ ! -z "$LFS_FILE" ]; then if [ ! -z "$LFS_FILE" ]; then
LFS_FILES="$LFS_FILES $LFS_FILE" LFS_FILES+=("$LFS_FILE")
fi fi
done <<< "$CHANGED_FILES" done
if [ -z "$LFS_FILES" ]; then if [ -z "$LFS_FILES" ]; then
exit 0 exit 0
fi fi
while read -r FILE; do for FILE in ${LFS_FILES[@]}
do
SOFT_SHA=$(git hash-object -w "$FILE") SOFT_SHA=$(git hash-object -w "$FILE")
RAW_SHA=$(git hash-object -w --no-filters "$FILE") RAW_SHA=$(git hash-object -w --no-filters "$FILE")
if [ $SOFT_SHA == $RAW_SHA ]; then if [ $SOFT_SHA == $RAW_SHA ]; then
BINARY_FILES="$FILE\n$BINARY_FILES" BINARY_FILES="$FILE\n$BINARY_FILES"
fi fi
done <<< "$LFS_FILES" done
if [[ -n "$BINARY_FILES" ]]; then if [[ -n "$BINARY_FILES" ]]; then
echo "Attention!" 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