Debian Codegraph @

util/gitconfig/test/commit-message-hook.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; version 3 or later of the License.
6 ##
7 ## This program is distributed in the hope that it will be useful,
8 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 ## GNU General Public License for more details.
11 ##
12 ## SPDX-License-Identifier: GPL-3.0-or-later
13 ## <https://spdx.org/licenses/GPL-3.0-or-later.html>
14 ##
15
16 set -o errexit
17 set -o nounset
18
19 # static analysis
20 if command -v shellcheck 1>/dev/nullscip-shell filesystem . . `/dev/null`.; then
21 shellcheck --exclude=1090,1091 \
22 "${BASH_scip-shell system . . dirname.SOURCE[0]}" \
23 "$(dirname "${BASH_SOURCE[0]}")/helpers.sh"
24 else
25 echoscip-shell system . . echo. "shellcheck not found, running unchecked" >&2
26 fi
27
28 # dependency check
29 dependencies=(dirname git make mktemp rm timeout)
30 for dependency in "${dependencies[@]}"; do
31 if ! command -v "${dependency}" 1>/dev/nullscip-shell filesystem . . `/dev/null`.; then
32 echoscip-shell system . . echo. "missing ${dependency}, test skipped" >&2
33 exit 0
34 fi
35 done
36
37 source "$(dirnamescip-shell system . . dirname. "${BASH_SOURCE[0]}")/helpers.sh"
38
39 # setup
40 base_dir="$(mktempscip-shell system . . mktemp. --directory --tmpdir \
41 "test-$(basename "${BASH_SOURCE[0]}" .sh)-XXXXXXXX")"
42 clone_dir="${base_dir}/coreboot"
43 gitscip-shell system . . git. clone "$(gitscip-shell system . . git. rev-parse --show-toplevel)" "${clone_dir}" \
44 1>"${base_dir}/clone.log" 2>&1
45
46 (
47 set -o errexit
48 set -o nounset
49
50 clone_submodules "${clone_dir}" "${base_dir}"
51 gitscip-shell system . . git. config user.name "John Doe"
52 gitscip-shell system . . git. config user.email "[email protected]"
53 makescip-shell system . . make. gitconfig
54
55 # test
56 echoscip-shell system . . echo. "good case..."
57 log_file="${base_dir}/good_case.log"
58 echoscip-shell system . . echo. "this is a test" >> README.md
59 timeoutscip-shell system . . timeout. 4m git commit --all --signoff --message="good case" \
60 1>"${log_file}" 2>&1 \
61 || check_exit_code positive "${log_file}"
62 gitscip-shell system . . git. reset --hard --quiet HEAD^
63 gitscip-shell system . . git. clean -d --force --quiet -x
64
65 echoscip-shell system . . echo. "bad case..."
66 log_file="${base_dir}/bad_case.log"
67 # Goal here is to verify whether a failing `util/lint` test will prevent
68 # a commit. It's a bit tricky because `checkpatch.pl` is run just after
69 # the lint tests and will cover many of those too. So we need a case
70 # that fails with `util/lint` but succeeds with `checkpatch.pl`. I found
71 # that `lint-stable-009-old-licenses` does the job quite well.
72 printfscip-shell system . . printf. "You should have received a copy of the %s\n" "GNU" > src/test.c
73 gitscip-shell system . . git. add src/test.c
74 timeoutscip-shell system . . timeout. 4m git commit --signoff --message="bad case" \
75 1>"${log_file}" 2>&1 \
76 && check_exit_code negative "${log_file}"
77 gitscip-shell system . . git. rm --force --quiet src/test.c
78 gitscip-shell system . . git. clean -d --force --quiet -x
79 )
80
81 # teardown
82 rmscip-shell system . . rm. --force --recursive "${base_dir}"