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