diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index e539335..2a039c0 100755 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -15,4 +15,15 @@ if [[ "$BRANCH" =~ ^(master|main|develop)$ ]]; then echo "You are on branch $BRANCH. Are you sure you want to commit to this branch?" echo "If so, commit with -n to bypass the pre-commit hook." exit 1 -fi \ No newline at end of file +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 +)