-
Notifications
You must be signed in to change notification settings - Fork 35
/
post-commit
executable file
·87 lines (82 loc) · 2.63 KB
/
post-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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
function execute_command {
cmd=$1
echo "Running ${cmd} ..."
eval ${cmd}
if [[ $? -ne 0 ]] ; then
echo "error: Please amend your patch until the command"
echo "${cmd}"
echo "completes with no issues reported"
exit 1
fi
}
MANIFEST_DIR=.git/`readlink .git/config | sed 's/projects\/.*/manifests/'`
#
# Run checkpatch after the commit on the git diff with HEAD^
# This hook looks for various script files in scripts directory
#
if [[ -e scripts/checkpatch ]] ; then
checkpatch_script=scripts/checkpatch
elif [[ -e scripts/checkpatch.py ]] ; then
checkpatch_script=scripts/checkpatch.py
elif [[ -e scripts/checkpatch.pl ]] ; then
checkpatch_script=scripts/checkpatch.pl
fi
if [[ -n ${checkpatch_script} ]] ; then
cmd="git format-patch -1 --stdout | ${checkpatch_script} -"
execute_command "${cmd}"
fi
checkpatch_script=
if [[ -e $MANIFEST_DIR/scripts/global_checkpatch ]] ; then
checkpatch_script=$MANIFEST_DIR/scripts/global_checkpatch
fi
if [[ -n ${checkpatch_script} ]] ; then
cmd="git format-patch -1 --stdout | ${checkpatch_script} -"
execute_command "${cmd}"
fi
#
# Run checkfiles after the commit on the files updated by the commit
# This hook looks for various script files in scripts directory
#
if [[ -e scripts/checkfiles ]] ; then
checkfiles_script=scripts/checkfiles
elif [[ -e scripts/checkfiles.py ]] ; then
checkfiles_script=scripts/checkfiles.py
elif [[ -e scripts/checkfiles.pl ]] ; then
checkfiles_script=scripts/checkfiles.pl
fi
if [[ -n ${checkfiles_script} ]] ; then
cmd="git diff --name-only HEAD^ | ${checkfiles_script} -"
execute_command "${cmd}"
fi
checkfiles_script=
if [[ -e $MANIFEST_DIR/scripts/global_checkfiles ]] ; then
checkfiles_script=$MANIFEST_DIR/scripts/global_checkfiles
fi
if [[ -n ${checkfiles_script} ]] ; then
cmd="git diff --name-only HEAD^ | ${checkfiles_script} -"
execute_command "${cmd}"
fi
#
# Run basic_unit_tests after the commit
# This hook looks for various script files in scripts directory
#
if [[ -e tests/basic_unit_tests ]] ; then
basic_unit_tests_script=tests/basic_unit_tests
elif [[ -e tests/basic_unit_tests.py ]] ; then
basic_unit_tests_script=tests/basic_unit_tests.py
elif [[ -e tests/basic_unit_tests.pl ]] ; then
basic_unit_tests_script=tests/basic_unit_tests.pl
fi
if [[ -n ${basic_unit_tests_script} ]] ; then
cmd=${basic_unit_tests_script}
execute_command "${cmd}"
fi
basic_unit_tests_script=
if [[ -e $MANIFEST_DIR/tests/global_basic_unit_tests ]] ; then
basic_unit_tests_script=$MANIFEST_DIR/tests/global_basic_unit_tests
fi
if [[ -n ${basic_unit_tests_script} ]] ; then
cmd=${basic_unit_tests_script}
execute_command "${cmd}"
fi