commit-msg 802 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env bash
  2. # Sanitize file first, by removing leading lines that are empty or start with a hash,
  3. # as `convco` currently does not do it automatically (but git will)
  4. # TODO: next release of convco should be able to do it automatically
  5. MESSAGE="$(
  6. while read -r line ; do
  7. # skip any initial comments (possibly from previous run)
  8. if [ -z "${body_detected:-}" ] && { [[ "$line" =~ ^#.*$ ]] || [ "$line" == "" ]; }; then
  9. continue
  10. fi
  11. body_detected="true"
  12. echo "$line"
  13. done < "$1"
  14. )"
  15. # convco fails on fixup!, so remove fixup! prefix
  16. MESSAGE="${MESSAGE#fixup! }"
  17. if ! convco check --from-stdin <<<"$MESSAGE" ; then
  18. >&2 echo "Please follow conventional commits(https://www.conventionalcommits.org)"
  19. >&2 echo "Use git commit <args> to fix your commit"
  20. exit 1
  21. fi