pre-commit.git-hook 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. #
  3. # To install this script, copy it to .git/hooks/pre-commit in local copy of
  4. # tor git repo and make sure it has permission to execute.
  5. #
  6. # This is pre-commit git hook script that prevents commiting your changeset if
  7. # it fails our code formatting, changelog entry formatting, module include
  8. # rules, or best practices tracker.
  9. workdir=$(git rev-parse --show-toplevel)
  10. cd "$workdir" || exit 1
  11. set -e
  12. if [ -n "$(ls ./changes/)" ]; then
  13. python scripts/maint/lintChanges.py ./changes/*
  14. fi
  15. if [ -d src/lib ]; then
  16. # This is the layout in 0.3.5
  17. perl scripts/maint/checkSpace.pl -C \
  18. src/lib/*/*.[ch] \
  19. src/core/*/*.[ch] \
  20. src/feature/*/*.[ch] \
  21. src/app/*/*.[ch] \
  22. src/test/*.[ch] \
  23. src/test/*/*.[ch] \
  24. src/tools/*.[ch]
  25. elif [ -d src/common ]; then
  26. # This was the layout before 0.3.5
  27. perl scripts/maint/checkSpace.pl -C \
  28. src/common/*/*.[ch] \
  29. src/or/*/*.[ch] \
  30. src/test/*.[ch] \
  31. src/test/*/*.[ch] \
  32. src/tools/*.[ch]
  33. fi
  34. if test -e scripts/maint/practracker/includes.py; then
  35. python scripts/maint/practracker/includes.py
  36. fi
  37. # Only call practracker if ${PT_DIR}/.enable_practracker_in_hooks exists
  38. # We do this check so that we can enable practracker in hooks in master, and
  39. # disable it on maint branches
  40. PT_DIR=scripts/maint/practracker
  41. if [ -e "${PT_DIR}/practracker.py" ]; then
  42. if [ -e "${PT_DIR}/.enable_practracker_in_hooks" ]; then
  43. if ! python3 "${PT_DIR}/practracker.py" "$workdir"; then
  44. exit 1
  45. fi
  46. fi
  47. fi