Files
dc/.git-hooks/pre-commit
allan fd55105f62
Some checks failed
Release / Build-production-and-ng-test (push) Successful in 4m20s
Release / release (push) Has been cancelled
Release / Build-and-test-development (push) Has been cancelled
chore(git): adding size check in precommit hook
2025-06-27 16:42:13 +01:00

23 lines
792 B
Bash
Executable File

#!/bin/sh
# Using `--silent` helps for showing any errs in the first line of the response
# The first line is picked up by the VS Code GIT UI popup when rc is not 0
if npm run --silent lint:check:silent ; then
exit 0
else
npm run --silent lint:fix:silent
echo "❌ Prettier check failed! We ran lint:fix for you. Please add & commit again."
exit 1
fi
## Avoid large commits
# https://www.backblaze.com/blog/how-many-bytes-are-in-a-megabyte-really/
size_limit=$((2 * 2**20)) # 2mbs
# https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---disk-usage
commit_size=$(git rev-list --disk-usage HEAD^..HEAD)
test "$commit_size" -lt "$size_limit" || (
echo "Commit size is too large: $commit_size > $size_limit"
echo "Force commit using --no-verify"
exit 1
)