Skip to content
File

Blob: githooks/pre-commit

bash53 lines
1#!/bin/bash
2 
3cd "$(git rev-parse --show-toplevel)"
4DISALLOWED_PATTERN='KJ_DBG'
5 
6if git diff-index -G"$DISALLOWED_PATTERN" --cached HEAD --diff-filter=AM -U0 | grep -i --color -E "$DISALLOWED_PATTERN"
7then
8 echo -e "\nERROR, KJ_DBG is not allowed in checked-in source code:"
9 echo -e " see https://github.com/capnproto/capnproto/blob/v2/c%2B%2B/src/kj/debug.h#L42\n"
10 echo -e "To commit anyway, use --no-verify\n"
11 exit 1
12fi
13 
14clang_format_check() {
15 source "$(dirname -- $BASH_SOURCE)/../tools/unix/find-python3.sh"
16 PYTHON_PATH=$(get_python3)
17 if [[ -z "$PYTHON_PATH" ]]; then
18 echo
19 echo "python3 is required for formatting and was not found"
20 echo
21 echo "ERROR: you must either install python3 and try pushing again or run `git push` with `--no-verify`"
22 return 1
23 fi
24 
25 set +e
26 $PYTHON_PATH "$(dirname -- $BASH_SOURCE)/../tools/cross/format.py" --check git --staged
27 EXIT_CODE=$?
28 set -e
29 case $EXIT_CODE in
30 0)
31 # No lint.
32 return 0
33 ;;
34 1)
35 echo
36 echo "ERROR: changes staged for commit have lint. Pass '--no-verify' or '-n' to skip."
37 echo
38 echo "To fix lint:"
39 echo " just format"
40 echo
41 return 1
42 ;;
43 2)
44 echo
45 echo "ERROR: failed to run format.py, Pass '--no-verify' or '-n' to skip."
46 echo
47 return 1
48 ;;
49 esac
50}
51 
52clang_format_check