<p>Alex Thiessen has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/23281">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">util/gitconfig/test: Add commit-msg hook test<br><br>Add a test that, after cloning the repository to a temporary directory,<br>installs git hooks and attempts to do a good and a bad commit, expecting<br>the former to succeed and the latter to fail, thus testing the<br>`commit-msg` hook.<br><br>Change-Id: Icdaf0109c60cb5b6952b1a2468ab050a742e4201<br>Signed-off-by: Alex Thiessen <alex.thiessen.de+coreboot@gmail.com><br>---<br>A util/gitconfig/test/commit-message-hook.sh<br>1 file changed, 87 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/81/23281/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/gitconfig/test/commit-message-hook.sh b/util/gitconfig/test/commit-message-hook.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..b37262d</span><br><span>--- /dev/null</span><br><span>+++ b/util/gitconfig/test/commit-message-hook.sh</span><br><span>@@ -0,0 +1,87 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/bin/bash</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+## This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+## Copyright (C) 2003-2018 Alex Thiessen <alex.thiessen.de+coreboot@gmail.com></span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+## This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+## it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+## the Free Software Foundation; version 3 or later of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+## This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+## but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+## GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+## SPDX-License-Identifier: GPL-3.0-or-later</span><br><span style="color: hsl(120, 100%, 40%);">+## <https://spdx.org/licenses/GPL-3.0-or-later.html></span><br><span style="color: hsl(120, 100%, 40%);">+##</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+set -o errexit</span><br><span style="color: hsl(120, 100%, 40%);">+set -o nounset</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# statical analysis</span><br><span style="color: hsl(120, 100%, 40%);">+if command -v shellcheck 1>/dev/null; then</span><br><span style="color: hsl(120, 100%, 40%);">+       shellcheck --exclude=1090,1091 \</span><br><span style="color: hsl(120, 100%, 40%);">+              "${BASH_SOURCE[0]}" \</span><br><span style="color: hsl(120, 100%, 40%);">+               "$(dirname "${BASH_SOURCE[0]}")/helpers.sh"</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "shellcheck not found, running unchecked" >&2</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# dependency check</span><br><span style="color: hsl(120, 100%, 40%);">+dependencies=(dirname git make mktemp rm timeout)</span><br><span style="color: hsl(120, 100%, 40%);">+for dependency in "${dependencies[@]}"; do</span><br><span style="color: hsl(120, 100%, 40%);">+        if ! command -v "${dependency}" 1>/dev/null; then</span><br><span style="color: hsl(120, 100%, 40%);">+                echo "missing ${dependency}, test skipped" >&2</span><br><span style="color: hsl(120, 100%, 40%);">+               exit 0</span><br><span style="color: hsl(120, 100%, 40%);">+        fi</span><br><span style="color: hsl(120, 100%, 40%);">+done</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+source "$(dirname "${BASH_SOURCE[0]}")/helpers.sh"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# setup</span><br><span style="color: hsl(120, 100%, 40%);">+base_dir="$(mktemp --directory --tmpdir \</span><br><span style="color: hsl(120, 100%, 40%);">+ "test-$(basename "${BASH_SOURCE[0]}" .sh)-XXXXXXXX")"</span><br><span style="color: hsl(120, 100%, 40%);">+clone_dir="${base_dir}/coreboot"</span><br><span style="color: hsl(120, 100%, 40%);">+git clone "$(git rev-parse --show-toplevel)" "${clone_dir}" \</span><br><span style="color: hsl(120, 100%, 40%);">+  1>"${base_dir}/clone.log" 2>&1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+(</span><br><span style="color: hsl(120, 100%, 40%);">+      set -o errexit</span><br><span style="color: hsl(120, 100%, 40%);">+        set -o nounset</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      clone_submodules "${clone_dir}" "${base_dir}"</span><br><span style="color: hsl(120, 100%, 40%);">+     git config user.name "John Doe"</span><br><span style="color: hsl(120, 100%, 40%);">+     git config user.email "john.doe@example.com"</span><br><span style="color: hsl(120, 100%, 40%);">+        make gitconfig</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      # test</span><br><span style="color: hsl(120, 100%, 40%);">+        echo "good case..."</span><br><span style="color: hsl(120, 100%, 40%);">+ log_file="${base_dir}/good_case.log"</span><br><span style="color: hsl(120, 100%, 40%);">+        echo "this is a test" >> README</span><br><span style="color: hsl(120, 100%, 40%);">+       timeout 4m git commit --all --signoff --message="good case" \</span><br><span style="color: hsl(120, 100%, 40%);">+               1>"${log_file}" 2>&1 \</span><br><span style="color: hsl(120, 100%, 40%);">+            || check_exit_code positive "${log_file}"</span><br><span style="color: hsl(120, 100%, 40%);">+   git reset --hard --quiet HEAD^</span><br><span style="color: hsl(120, 100%, 40%);">+        git clean -d --force --quiet -x</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     echo "bad case..."</span><br><span style="color: hsl(120, 100%, 40%);">+  log_file="${base_dir}/bad_case.log"</span><br><span style="color: hsl(120, 100%, 40%);">+ # Goal here is to verify whether a failing `util/lint` test will prevent</span><br><span style="color: hsl(120, 100%, 40%);">+      # a commit. It's a bit tricky because `checkpatch.pl` is run just after</span><br><span style="color: hsl(120, 100%, 40%);">+   # the lint tests and will cover many of those too. So we need a case</span><br><span style="color: hsl(120, 100%, 40%);">+  # that fails with `util/lint` but succeeds with `checkpatch.pl`. I found</span><br><span style="color: hsl(120, 100%, 40%);">+      # that `lint-stable-009-old-licenses` does the job quite well.</span><br><span style="color: hsl(120, 100%, 40%);">+        printf "You should have received a copy of the %s\n" "GNU" > src/test.c</span><br><span style="color: hsl(120, 100%, 40%);">+        git add src/test.c</span><br><span style="color: hsl(120, 100%, 40%);">+    timeout 4m git commit --signoff --message="bad case" \</span><br><span style="color: hsl(120, 100%, 40%);">+              1>"${log_file}" 2>&1 \</span><br><span style="color: hsl(120, 100%, 40%);">+            && check_exit_code negative "${log_file}"</span><br><span style="color: hsl(120, 100%, 40%);">+   git rm --force --quiet src/test.c</span><br><span style="color: hsl(120, 100%, 40%);">+     git clean -d --force --quiet -x</span><br><span style="color: hsl(120, 100%, 40%);">+)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# teardown</span><br><span style="color: hsl(120, 100%, 40%);">+rm --force --recursive "${base_dir}"</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/23281">change 23281</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/23281"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Icdaf0109c60cb5b6952b1a2468ab050a742e4201 </div>
<div style="display:none"> Gerrit-Change-Number: 23281 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alex Thiessen <alex.thiessen.de+coreboot@gmail.com> </div>