check_commit_msgs.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # Checks the commits msgs in the range of commits travis is testing.
  3. # Based heavily on
  4. # https://github.com/JensRantil/angular.js/blob/ffe93bb368037049820ac05ef62f8cc7ed379d98/test-commit-msgs.sh
  5. # Travis's docs are misleading.
  6. # Check for either a commit or a range (which apparently isn't always a range) and fix as needed.
  7. if [ "$#" -gt 0 ]; then
  8. RANGE=$1
  9. elif [ "$TRAVIS_COMMIT_RANGE" != "" ]; then
  10. RANGE=$TRAVIS_COMMIT_RANGE
  11. elif [ "$TRAVIS_COMMIT" != "" ]; then
  12. RANGE=$TRAVIS_COMMIT
  13. fi
  14. if [ "$RANGE" == "" ]; then
  15. echo -n "RANGE is empty!"
  16. exit 1
  17. fi
  18. # Travis sends the ranges with 3 dots. Git only wants 2.
  19. if [[ "$RANGE" == *...* ]]; then
  20. RANGE=`echo $TRAVIS_COMMIT_RANGE | sed 's/\.\.\./../'`
  21. elif [[ "$RANGE" != *..* ]]; then
  22. RANGE="$RANGE~..$RANGE"
  23. fi
  24. EXIT=0
  25. for sha in `git log --format=oneline "$RANGE" | cut '-d ' -f1`
  26. do
  27. echo -n "Checking commit message for $sha ... "
  28. git log --format=%B -n 1 $sha | php ./.scripts/validate_commit_msg.php
  29. VALUE=$?
  30. if [ "$VALUE" -gt 0 ]; then
  31. echo -n "./.scripts/validate_commit_msg.php exited with error!"
  32. EXIT=$VALUE
  33. fi
  34. done
  35. exit $EXIT