Skip to content

Commit

Permalink
Make capitalization check work with 'nocasematch' on
Browse files Browse the repository at this point in the history
Bash has an option, 'nocasematch' (see 'help shopt') that makes pattern
matching case-insensitive. So, the check for "subject line capitalized"
  [[ ${subject} =~ ^[[:lower:]] ]]
will report a non-capitalized subject whenever the subject line starts
with an ASCII letter, lowercase or uppercase, that is, basically always.

As far as I know, 'nocasematch' is rarely on. However, if it is on,
without this fix it would produce a very confusing error message.
For example,

$ git commit -m "Add HTTP client"
ERROR: commit message not properly formatted
- line 1: subject not capitalized
  Add HTTP client
  • Loading branch information
laurivan committed Jun 13, 2024
1 parent e83eaf5 commit 8b66c32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lint-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ while true; do
# errors that only confuse the user.

# Capitalization check
shopt -u nocasematch
[[ ${subject} =~ ^[[:lower:]] ]] &&
append_error \
"${error_subject_not_capitalized}" \
Expand Down
11 changes: 11 additions & 0 deletions test/cases/subject-line-capitalization.test
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ EOF
call lint-commit-msg msg.txt
expect_success
}

test_capitalized_with_nocasematch() {
cat > msg.txt <<EOF
Start with an uppercase letter
EOF
shopt -s nocasematch
export BASHOPTS

call lint-commit-msg msg.txt
expect_success
}

0 comments on commit 8b66c32

Please sign in to comment.