prepare-commit-msg 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. #
  3. # Prepare git commit message:
  4. # - Add [ci skip] if the changes seem irrelevant for continuous integration
  5. # Add [ci skip] to the commit message unless there are changes to files
  6. # that are relevant for testing such as src/*, test/*, ledger3.texi, ...
  7. add_ci_skip ()
  8. {
  9. pattern="$1"; shift
  10. source="$1"
  11. # Don't add [ci skip] if it's already in the commit message source
  12. grep '\[ci skip\]' "$source" >/dev/null 2>&1
  13. [ $? -eq 0 ] && return
  14. if [ $(git diff --cached --name-only | grep --count "$pattern") -eq 0 ]; then
  15. tempfile=$(mktemp "${0}.XXXXXX")
  16. cat - "$1" <<EOF > "$tempfile"
  17. # It seems the changes to be committed are irrelevant for the continuous
  18. # integration, therefore it will be skipped for this commit.
  19. #
  20. # If you still want continuous integration to run for this commit
  21. # comment or remove the next line.
  22. [ci skip]
  23. EOF
  24. mv "$tempfile" "$source"
  25. fi
  26. }
  27. ## MAIN
  28. file="$1"
  29. source="$2"
  30. # Skip merge commits
  31. [ "$source" = "merge" ] && exit 0
  32. add_ci_skip '\(^src\|^test\|^doc/ledger3.texi\|^\.travis.yml\|CMakeLists.txt\)' "$file"