pre-commit.git-hook 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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
  48. if [ -e scripts/maint/checkShellScripts.sh ]; then
  49. scripts/maint/checkShellScripts.sh
  50. fi