Skip to content

Commit 2e0e9f3

Browse files
committed
Ignore trailing whitespace in commit messages
Because: * `git` strips trailing whitespace from commit messages, therefore the message validation should ignore these as well. This change: * Uses `shopt extglob` and bash parameter expansion to avoid adding a dependency on `sed` or `tr`, ref: http://www.cyberciti.biz/faq/bash-remove-whitespace-from-string/ Notes: * This is hard to test. Both the `-m` and `-F` `git-commit` args strip whitespace before the commit-msg hook is called. The only way I can find to persist the trailing whitespace into the commit-msg hook is via `nano`, which is difficult to drive with bats. Fixes #1
1 parent 070b263 commit 2e0e9f3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

hook.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,16 @@ read_commit_msg() {
8989

9090
# read commit message into lines array
9191
while IFS= read -r; do
92+
93+
# trim trailing spaces from commit lines
94+
shopt -s extglob
95+
REPLY="${REPLY%%*( )}"
96+
shopt -u extglob
97+
98+
# ignore comments
9299
[[ $REPLY =~ ^# ]]
93100
test $? -eq 0 || COMMIT_MSG_LINES+=("$REPLY")
101+
94102
done < <(cat $COMMIT_MSG_FILE)
95103
}
96104

0 commit comments

Comments
 (0)