commit-msg 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #echo Checking git message in $1
  3. usage="\n
  4. Please see the guidelines for git commit messages in the CONTRIBUTORS file\n
  5. Your git commit message should start with a line of the form\n
  6. \n
  7. HPCC-XXXX Short description\n
  8. \n
  9. where XXXX is the Jira issue number that this commit is referencing, and\n
  10. short description is a brief description of the issue that will appear in\n
  11. the --oneline version of the generated changelog.\n
  12. \n
  13. Use git commit -s -t $1 to reopen previous message for editing\n"
  14. (head -1 "$1" | grep -E -q "^HPCC-[0-9]+ |^Merge ") || {
  15. echo >&2 "\n ERROR: Missing Jira issue on beginning of first line (HPCC-XXXX)"
  16. echo >&2 $usage
  17. exit 1
  18. }
  19. (head -1 "$1" | grep -E -q "[^.]$") || {
  20. echo >&2 "\n ERROR: Please don't use . at the end of the short description"
  21. echo >&2 $usage
  22. exit 1
  23. }
  24. (head -1 "$1" | grep -E -q "^HPCC-[0-9]+ [^a-z]|^Merge ") || {
  25. echo >&2 "\n ERROR: Short description should start with a capital"
  26. echo >&2 $usage
  27. exit 1
  28. }
  29. (head -2 "$1" | tail -1 | grep -E -q "^$") || {
  30. echo >&2 "\n ERROR: Short description must be followed by a blank line. Have you signed your commit?"
  31. echo >&2 $usage
  32. exit 1
  33. }
  34. [ $(grep -v '^#' "$1" | wc -L ) -le 80 ] || {
  35. echo >&2 "\n ERROR: Commit message lines too long (max 80 chars)."
  36. echo >&2 $usage
  37. exit 1
  38. }
  39. (grep -q "^Signed-off-by: " "$1") || {
  40. echo >&2 "\n ERROR: Commit not signed. All commits should be signed (use git commit -s)."
  41. echo >&2 $usage
  42. exit 1
  43. }