Last active
June 26, 2023 13:20
-
-
Save eikevons/6c4d490bcf6d36422ae624f6aa01bf0d to your computer and use it in GitHub Desktop.
Revisions
-
eikevons renamed this gist
Jun 26, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
eikevons created this gist
Jun 25, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/bin/sh # Maximum file size limit in MiB limitMiB=${GIT_MAX_MIB:-5} # Default 5MiB if [ $limitMiB -le 0 ]; then exit 0 fi # Go to repo root folder cd "$(git rev-parse --show-toplevel)" git diff-index --cached --name-only HEAD | { fail=0 while read file; do sizeMiB=$(( $(stat -c '%s' "$file") / 1024 / 1024 )) if [ $sizeMiB -gt $limitMiB ]; then if [ $fail = 0 ]; then echo "Some files exceed size limit of $limitMiB MiB:" 1>&2 echo 1>&2 fail=1 fi echo "$file ($sizeMiB MiB)" 1>&2 fi done if [ "$fail" = 1 ];then echo 1>&2 echo "(Use 'GIT_MAX_MIB=... git commit ...' to use a different limit. GIT_MAX_MIB=0 disables this hook.)" 1>&2 exit 1 fi } fail=$? exit $fail