Last active
November 24, 2022 06:48
-
-
Save expelledboy/b20da879b1fa5a2a68a25f9568c4e877 to your computer and use it in GitHub Desktop.
Git pre-commit hook that rejects commits that are too large
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -eou pipefail | |
# 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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@simonseo Yes, I am guessing that your repo doesn't have more than 2 commits?