commit-msg 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. #
  3. # This is an example Git hook for use with Rush. To enable this hook, rename this file
  4. # to "commit-msg" and then run "rush install", which will copy it from common/git-hooks
  5. # to the .git/hooks folder.
  6. #
  7. # TO LEARN MORE ABOUT GIT HOOKS
  8. #
  9. # The Git documentation is here: https://git-scm.com/docs/githooks
  10. # Some helpful resources: https://githooks.com
  11. #
  12. # ABOUT THIS EXAMPLE
  13. #
  14. # The commit-msg hook is called by "git commit" with one argument, the name of the file
  15. # that has the commit message. The hook should exit with non-zero status after issuing
  16. # an appropriate message if it wants to stop the commit. The hook is allowed to edit
  17. # the commit message file.
  18. # This example enforces that commit message should contain a minimum amount of
  19. # description text.
  20. # if [ `cat $1 | wc -w` -lt 3 ]; then
  21. # echo ""
  22. # echo "Invalid commit message: The message must contain at least 3 words."
  23. # exit 1
  24. # fi
  25. # rebase 过程中分支名格式为 (no branch, rebasing chore/replace-rushtool)
  26. # 正常提交时分支名格式为 chore/replace-rushtool
  27. BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
  28. # 如果匹配到 rebase 格式的输出,认为是在rebase ,则跳过自动推送
  29. if [[ "X${BRANCH_NAME}" == "X(no branch"* ]]; then
  30. exit
  31. else
  32. node common/scripts/install-run-rush.js -q commitlint \
  33. --config common/autoinstallers/rush-commitlint/commitlint.config.js \
  34. --edit "$1" || exit 1
  35. fi