Skip to content

Commit 284a969

Browse files
author
Amir Ghorbanian
committed
Linter to check commit message formatting
Write linter to check that commit messages have a new line before the body or no body at all. reference: gist.github.com/agnivade/67b42d664ece2d4210c7 Fixes issue #19091.
1 parent 3276c14 commit 284a969

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)