pre-commit 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # Git pre-commit hook that runs multiple hooks specified in $HOOKS.
  3. # Make sure this script is executable. Bypass hooks with git commit --no-verify.
  4. # This file is part of a set of unofficial pre-commit hooks available
  5. # at github.
  6. # Link: https://github.com/githubbrowser/Pre-commit-hooks
  7. # Contact: David Martin, david.martin.mailbox@googlemail.com
  8. ###########################################################
  9. # CONFIGURATION:
  10. # pre-commit hooks to be executed. They should be in the same .git/hooks/ folder
  11. # as this script. Hooks should return 0 if successful and nonzero to cancel the
  12. # commit. They are executed in the order in which they are listed.
  13. #HOOKS="pre-commit-compile pre-commit-uncrustify"
  14. HOOKS="pre-commit-clang-format"
  15. ###########################################################
  16. # There should be no need to change anything below this line.
  17. . "$(dirname -- "$0")/canonicalize_filename.sh"
  18. # exit on error
  19. set -e
  20. # Absolute path to this script, e.g. /home/user/bin/foo.sh
  21. SCRIPT="$(canonicalize_filename "$0")"
  22. # Absolute path this script is in, thus /home/user/bin
  23. SCRIPTPATH="$(dirname -- "$SCRIPT")"
  24. for hook in $HOOKS
  25. do
  26. echo "Running hook: $hook"
  27. # run hook if it exists
  28. # if it returns with nonzero exit with 1 and thus abort the commit
  29. if [ -f "$SCRIPTPATH/$hook" ]; then
  30. "$SCRIPTPATH/$hook"
  31. if [ $? != 0 ]; then
  32. exit 1
  33. fi
  34. else
  35. echo "Error: file $hook not found."
  36. echo "Aborting commit. Make sure the hook is in $SCRIPTPATH and executable."
  37. echo "You can disable it by removing it from the list in $SCRIPT."
  38. echo "You can skip all pre-commit hooks with --no-verify (not recommended)."
  39. exit 1
  40. fi
  41. done