forked from pre-commit/pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit-hook
More file actions
executable file
·56 lines (44 loc) · 1.03 KB
/
Copy pathpre-commit-hook
File metadata and controls
executable file
·56 lines (44 loc) · 1.03 KB
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
#!/usr/bin/env bash
# This is a randomish md5 to identify this script
# 49fd668cb42069aa1b6048464be5d395
pushd `dirname $0` > /dev/null
HERE=`pwd`
popd > /dev/null
retv=0
ENV_PYTHON='{sys_executable}'
which pre-commit >& /dev/null
WHICH_RETV=$?
"$ENV_PYTHON" -c 'import pre_commit.main' >& /dev/null
ENV_PYTHON_RETV=$?
python -c 'import pre_commit.main' >& /dev/null
PYTHON_RETV=$?
if ((
(WHICH_RETV != 0) &&
(ENV_PYTHON_RETV != 0) &&
(PYTHON_RETV != 0)
)); then
echo '`pre-commit` not found. Did you forget to activate your virtualenv?'
exit 1
fi
# Run the legacy pre-commit if it exists
if [ -x "$HERE"/pre-commit.legacy ]; then
"$HERE"/pre-commit.legacy
if [ $? -ne 0 ]; then
retv=1
fi
fi
# Run pre-commit
if ((WHICH_RETV == 0)); then
pre-commit
PRE_COMMIT_RETV=$?
elif ((ENV_PYTHON_RETV == 0)); then
"$ENV_PYTHON" -m pre_commit.main
PRE_COMMIT_RETV=$?
else
python -m pre_commit.main
PRE_COMMIT_RETV=$?
fi
if ((PRE_COMMIT_RETV != 0)); then
retv=1
fi
exit $retv