From e54de44d4b1610fadc09dd531c0c22745e651826 Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:46:24 +0100 Subject: [PATCH] chore: adding git precommit hook to avoid large files --- .git-hooks/pre-commit | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 +)