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.
6 # This is pre-commit git hook script that prevents committing your changeset if
7 # it fails our code formatting, changelog entry formatting, module include
10 # Run only if this environment variable is set.
11 if [ -z "$TOR_EXTRA_PRE_COMMIT_CHECKS" ]; then
15 workdir
=$
(git rev-parse
--show-toplevel)
17 cd "$workdir" ||
exit 1
22 # When called in pre-commit, check the files modified in this commit
23 CHECK_FILTER
="git diff --cached --name-only --diff-filter=ACMR"
24 # Use the appropriate owned tor source list to filter the changed files
26 # This is the layout in 0.3.5 and later.
28 # Keep these lists consistent:
29 # - OWNED_TOR_C_FILES in Makefile.am
30 # - CHECK_FILES in pre-commit.git-hook and pre-push.git-hook
31 # - try_parse in check_cocci_parse.sh
32 CHECK_FILES
="$($CHECK_FILTER \
35 src/feature/*/*.[ch] \
42 # When called in pre-push, concatenate the argument array
43 # Fails on special characters in file names
47 ## General File Checks
49 if [ -n "$(ls ./changes/)" ]; then
50 python
scripts
/maint
/lintChanges.py .
/changes
/*
53 if [ -e scripts
/maint
/checkShellScripts.sh
]; then
54 scripts
/maint
/checkShellScripts.sh
57 if [ -e scripts
/maint
/checkSpaceTest.sh
]; then
58 scripts
/maint
/checkSpaceTest.sh
61 if [ ! "$CHECK_FILES" ]; then
62 echo "No modified tor-owned source files, skipping further checks"
66 ## Owned Source File Checks
68 printf "Modified tor-owned source files:\\n%s\\n" "$CHECK_FILES"
70 # We want word splitting here, because file names are space separated
71 # shellcheck disable=SC2086
72 perl
scripts
/maint
/checkSpace.pl
-C \
75 # This makes sure that we are only including things we're allowed to include.
76 if test -e scripts
/maint
/practracker
/includes.py
; then
77 python
scripts
/maint
/practracker
/includes.py
80 if [ -e scripts
/coccinelle
/check_cocci_parse.sh
]; then
82 # Run a verbose cocci parse check on the changed files
83 # (spatch is slow, so we don't want to check all the files.)
85 # We want word splitting here, because file names are space separated
86 # shellcheck disable=SC2086
87 VERBOSE
=1 scripts
/coccinelle
/check_cocci_parse.sh \