commit-msg 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. #
  3. # Every commit should have an issue reference at the start of the first line:
  4. echo Checking git message in $1
  5. (head -1 "$1" | grep -E -q "^gh-[0-9]+ ") || {
  6. echo >&2 "Missing GitHub issue"
  7. echo >&2 ""
  8. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file"
  9. echo >&2 "Your git commit message should start with a line of the form"
  10. echo >&2 ""
  11. echo >&2 "gh-XXXX Short description"
  12. echo >&2 ""
  13. echo >&2 "where XXXX is the github issue number that this commit is referencing, and"
  14. echo >&2 "short description is a brief description of the issue that will appear in"
  15. echo >&2 "the --oneline version of the generated changelog."
  16. echo >&2 ""
  17. echo >&2 "Use git commit -s -t .git/COMMIT_EDITMSG to reopen previous message for editing"
  18. exit 1
  19. }
  20. (head -1 "$1" | grep -E -q "[^.]$") || {
  21. echo >&2 "Please don't use . at the end of the short description"
  22. echo >&2 ""
  23. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file"
  24. echo >&2 "Your git commit message should start with a line of the form"
  25. echo >&2 ""
  26. echo >&2 "gh-XXXX Short description"
  27. echo >&2 ""
  28. echo >&2 "where XXXX is the github issue number that this commit is referencing, and"
  29. echo >&2 "short description is a brief description of the issue that will appear in"
  30. echo >&2 "the --oneline version of the generated changelog."
  31. echo >&2 ""
  32. echo >&2 "Use git commit -s -t .git/COMMIT_EDITMSG to reopen previous message for editing"
  33. exit 1
  34. }
  35. (head -1 "$1" | grep -E -q "^gh-[0-9]+ [^a-z]") || {
  36. echo >&2 "Short description should start with a capital"
  37. echo >&2 ""
  38. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file"
  39. echo >&2 "Your git commit message should start with a line of the form"
  40. echo >&2 ""
  41. echo >&2 "gh-XXXX Short description"
  42. echo >&2 ""
  43. echo >&2 "where XXXX is the github issue number that this commit is referencing, and"
  44. echo >&2 "short description is a brief description of the issue that will appear in"
  45. echo >&2 "the --oneline version of the generated changelog."
  46. echo >&2 ""
  47. echo >&2 "Use git commit -s -t .git/COMMIT_EDITMSG to reopen previous message for editing"
  48. exit 1
  49. }
  50. (head -2 "$1" | tail -1 | grep -E -q "^$") || {
  51. echo >&2 "Short description must be followed by a blank line"
  52. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file"
  53. exit 1
  54. }
  55. [ $(cat "$1" | wc -L ) -le 80 ] || {
  56. echo >&2 "Commit message lines too long."
  57. echo >&2 ""
  58. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file."
  59. echo >&2 "Lines in the commit message should be no longer than 80 characters."
  60. echo >&2 ""
  61. echo >&2 "Use git commit -s -t .git/COMMIT_EDITMSG to reopen previous message for editing"
  62. exit 1
  63. }
  64. (grep -q "^Signed-off-by: " "$1") || {
  65. echo >&2 "Commit not signed."
  66. echo >&2 ""
  67. echo >&2 "Please see the guidelines for git commit messages in the CONTRIBUTORS file."
  68. echo >&2 "All commits should be signed (use git commit -s)."
  69. echo >&2 ""
  70. echo >&2 "Use git commit -s -t .git/COMMIT_EDITMSG to reopen previous message for editing"
  71. exit 1
  72. }