Compare commits

...

2 Commits

Author SHA1 Message Date
Uladzimir Havenchyk
f3f68167c2 Merge branch 'master' into check-empty-files 2025-03-24 17:41:01 +03:00
Uladzimir Havenchyk
2128ab6034 chore: add pre-commit check on empty file 2025-03-21 14:18:03 +03:00
2 changed files with 40 additions and 1 deletions

View File

@@ -9,4 +9,7 @@ yarn precommit
# ATM, you can manually run ./bin/cljfmt_staged.sh if you want to format locally staged files and inspect after.
# ./bin/cljfmt_staged.sh
./hooks/pre-commit.nocommit
# Check for empty files
./bin/check-empty-files.sh
./hooks/pre-commit.nocommit

36
bin/check-empty-files.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/sh
# Check for empty files in staged changes
# Exit with error if any empty files are found
# Redirect output to stderr
exec 1>&2
# ANSI color codes
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get list of staged files that are being added or modified
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
# Flag to track if we found any empty files
EMPTY_FILES_FOUND=0
for file in $STAGED_FILES; do
# Check if file exists and is empty
if [ -f "$file" ] && [ ! -s "$file" ]; then
if [ $EMPTY_FILES_FOUND -eq 0 ]; then
echo "${RED}Error: Empty files detected in commit:${NC}"
fi
echo "${RED}\t$file${NC}"
EMPTY_FILES_FOUND=1
fi
done
if [ $EMPTY_FILES_FOUND -eq 1 ]; then
echo "${RED}Please remove empty files before committing (add --no-verify to bypass)${NC}"
exit 1
fi
exit 0