pre-commit 757 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. #flutter format .
  3. ##https://gist.github.com/benmccallum/28e4f216d9d72f5965133e6c43aaff6e
  4. limit=$(( 1 * 2**20 )) # 1MB
  5. function file_too_large(){
  6. filename=$0
  7. filesize=$(( $1 / 2**20 ))
  8. cat <<HEREDOC
  9. File $filename is $filesize MB, which is larger than github's maximum
  10. file size (1 MB). We will not be able to push this file to GitHub.
  11. Commit aborted
  12. HEREDOC
  13. }
  14. empty_tree=$( git hash-object -t tree /dev/null )
  15. if git rev-parse --verify HEAD > /dev/null 2>&1
  16. then
  17. against=HEAD
  18. else
  19. against=empty_tree
  20. fi
  21. for file in $( git diff-index --cached --name-only $against ); do
  22. file_size=$( ls -la $file | awk '{ print $5 }')
  23. if [ "$file_size" -gt "$limit" ]; then
  24. file_too_large $filename $file_size
  25. exit 1;
  26. fi
  27. done