-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·60 lines (49 loc) · 1.22 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
######################
# ---- SETTINGS ---- #
######################
# standard path if you are using virtualenvwrapper;
# replace VENV_PATH appropriately if not
PROJECT_NAME=""
VENV_PATH="${HOME}/.virtualenvs/${PROJECT_NAME}"
# run these hooks in this order
hook_names=(
'isort'
'whitespace'
'forbidden'
'todo'
'flake8'
'black'
)
#### END SETTINGS ####
# check if commit just edits commit message,
# i.e. is a "REWORD", and if so, skip checks
if git diff --staged --quiet ; then
exit 0
fi
# if not inside virtual env, this will ensure
# it activates, so hooks will run correctly,
# e.g. isort hook needs to run inside the
# virtual env so it can properly identify
# 3rd party packages
if [ -z "$VIRTUAL_ENV" ]; then
source "${VENV_PATH}/bin/activate"
fi
exit_codes=()
# run each hook, storing the exit status, so
# we identify all issues
for hook_name in "${hook_names[@]}"; do
hook=".git/hooks/pre-commit-${hook_name}"
if [ -x "$hook" ]; then
"./$hook"
exit_codes+=($?)
else
echo "$hook is not executable"
exit_codes+=(1)
continue
fi
done
for status in "${exit_codes[@]}"; do
[ "$status" -eq 0 ] || exit "$status"
done
exit 0