Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions scripts/githooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ limit=${GIT_FILE_SIZE_LIMIT:-2000000} # Default 2MB
limitInMB=$(( $limit / 1000000 ))

function file_too_large(){
filename=$0
filename=$file
filesize=$(( $1 / 2**20 ))

filesize=$(( $1 \/ 2**20 ))\ncat <<HEREDOC

file_too_large $filesize $filename

File $filename is $filesize MB, which is larger than github's maximum
file size (20 MB). We will not be able to push this file to GitHub.
The maximum file size allowed is 2MB.
Expand All @@ -97,14 +99,16 @@ for file in $( git diff-index --cached --name-only $against ); do
if [ "$file_size" -gt "$limit" ]; then
printError "File $file is $(( $file_size / 10**6 )) MB, which is larger than our configured limit of $limitInMB MB"
shouldFail=true
exit 1
fi
done

if $shouldFail
then
printMessage "If you really need to commit this file, you can override the size limit by setting the GIT_FILE_SIZE_LIMIT environment variable, e.g. GIT_FILE_SIZE_LIMIT=20000000 for 20MB. Or, commit with the --no-verify switch to skip the check entirely."
printError "Commit aborted"
exit 1;
echo "For more information, refer to: https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694"
exit 1;
fi

if [[ ! $local_branch =~ $valid_branch_regex ]]
Expand Down