pre-commit 806 B

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