aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-07-30 17:32:33 +0200
committerMarcoFalke <falke.marco@gmail.com>2020-07-30 17:32:37 +0200
commitedec7f7c254294cd5c46ae5cf304353d458bb852 (patch)
tree63b484a4cd0ad7c2c06bfe623f3be156a3f29b8b /test
parentad2952d17a2af419a04256b10b53c7377f826a27 (diff)
parent284a969cc082ae3c63ab523f22e71da86ad4ab20 (diff)
Merge #19439: script: Linter to check commit message formatting
284a969cc082ae3c63ab523f22e71da86ad4ab20 Linter to check commit message formatting (Amir Ghorbanian) Pull request description: Write linter to check that commit messages have a new line before the body or no body at all. fixes issue #19091. ACKs for top commit: troygiorshev: ACK 284a969cc082ae3c63ab523f22e71da86ad4ab20 Reviewed, manually tested. Works great! fjahr: tested ACK 284a969cc082ae3c63ab523f22e71da86ad4ab20 adamjonas: utACK 284a969cc082ae3c63ab523f22e71da86ad4ab20 Tree-SHA512: fa278f090780b54e4fa6e2967a62b4c1a4da55d112ec1ad6dd7e1181ac490c5c1af0165524b5781b463fdd6d0f79fd3d95b5160184e6eca432ccff1189f77390
Diffstat (limited to 'test')
-rwxr-xr-xtest/lint/lint-git-commit-check.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/lint/lint-git-commit-check.sh b/test/lint/lint-git-commit-check.sh
new file mode 100755
index 0000000000..7cffd267dd
--- /dev/null
+++ b/test/lint/lint-git-commit-check.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+# Copyright (c) 2020 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#
+# Linter to check that commit messages have a new line before the body
+# or no body at all
+
+export LC_ALL=C
+
+EXIT_CODE=0
+
+while getopts "?" opt; do
+ case $opt in
+ ?)
+ echo "Usage: $0 [N]"
+ echo " TRAVIS_COMMIT_RANGE='<commit range>' $0"
+ echo " $0 -?"
+ echo "Checks unmerged commits, the previous N commits, or a commit range."
+ echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' $0"
+ exit ${EXIT_CODE}
+ ;;
+ esac
+done
+
+if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
+ if [ -n "$1" ]; then
+ TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
+ else
+ TRAVIS_COMMIT_RANGE="origin/master..HEAD"
+ fi
+fi
+
+while IFS= read -r commit_hash || [[ -n "$commit_hash" ]]; do
+ n_line=0
+ while IFS= read -r line || [[ -n "$line" ]]; do
+ n_line=$((n_line+1))
+ length=${#line}
+ if [ $n_line -eq 2 ] && [ $length -ne 0 ]; then
+ echo "The subject line of commit hash ${commit_hash} is followed by a non-empty line. Subject lines should always be followed by a blank line."
+ EXIT_CODE=1
+ fi
+ done < <(git log --format=%B -n 1 "$commit_hash")
+done < <(git log "${TRAVIS_COMMIT_RANGE}" --format=%H)
+
+exit ${EXIT_CODE}