Skip to content

Commit edec7f7

Browse files
author
MarcoFalke
committed
Merge #19439: script: Linter to check commit message formatting
284a969 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 284a969 Reviewed, manually tested. Works great! fjahr: tested ACK 284a969 adamjonas: utACK 284a969 Tree-SHA512: fa278f090780b54e4fa6e2967a62b4c1a4da55d112ec1ad6dd7e1181ac490c5c1af0165524b5781b463fdd6d0f79fd3d95b5160184e6eca432ccff1189f77390
2 parents ad2952d + 284a969 commit edec7f7

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/lint/lint-git-commit-check.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
#
6+
# Linter to check that commit messages have a new line before the body
7+
# or no body at all
8+
9+
export LC_ALL=C
10+
11+
EXIT_CODE=0
12+
13+
while getopts "?" opt; do
14+
case $opt in
15+
?)
16+
echo "Usage: $0 [N]"
17+
echo " TRAVIS_COMMIT_RANGE='<commit range>' $0"
18+
echo " $0 -?"
19+
echo "Checks unmerged commits, the previous N commits, or a commit range."
20+
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' $0"
21+
exit ${EXIT_CODE}
22+
;;
23+
esac
24+
done
25+
26+
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
27+
if [ -n "$1" ]; then
28+
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
29+
else
30+
TRAVIS_COMMIT_RANGE="origin/master..HEAD"
31+
fi
32+
fi
33+
34+
while IFS= read -r commit_hash || [[ -n "$commit_hash" ]]; do
35+
n_line=0
36+
while IFS= read -r line || [[ -n "$line" ]]; do
37+
n_line=$((n_line+1))
38+
length=${#line}
39+
if [ $n_line -eq 2 ] && [ $length -ne 0 ]; then
40+
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."
41+
EXIT_CODE=1
42+
fi
43+
done < <(git log --format=%B -n 1 "$commit_hash")
44+
done < <(git log "${TRAVIS_COMMIT_RANGE}" --format=%H)
45+
46+
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)