AppFlowy/.githooks/pre-commit

34 lines
757 B
Plaintext
Raw Normal View History

2021-07-06 11:56:56 +00:00
#!/usr/bin/env bash
#flutter format .
2021-07-08 06:14:03 +00:00
##https://gist.github.com/benmccallum/28e4f216d9d72f5965133e6c43aaff6e
limit=$(( 1 * 2**20 )) # 1MB
2021-07-06 11:56:56 +00:00
2021-07-08 06:14:03 +00:00
function file_too_large(){
filename=$0
filesize=$(( $1 / 2**20 ))
cat <<HEREDOC
File $filename is $filesize MB, which is larger than github's maximum
file size (1 MB). We will not be able to push this file to Github.
Commit aborted
HEREDOC
}
empty_tree=$( git hash-object -t tree /dev/null )
if git rev-parse --verify HEAD > /dev/null 2>&1
then
against=HEAD
else
against=empty_tree
fi
for file in $( git diff-index --cached --name-only $against ); do
file_size=$( ls -la $file | awk '{ print $5 }')
if [ "$file_size" -gt "$limit" ]; then
file_too_large $filename $file_size
exit 1;
fi
done