Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
494 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
#found in https://www.reddit.com/r/bash/comments/8inq6i/validate_git_commit_message/, contributed by user frakman1 | ||
#rules based on https://chris.beams.io/posts/git-commit/#seven-rules | ||
|
||
echo -e "\e[32m--- Checking Commit Message ---\e[0m"; | ||
|
||
cnt=0 | ||
while IFS='' read -r line || [[ -n "$line" ]]; do | ||
cnt=$((cnt+1)) | ||
length=${#line} | ||
if [ $cnt -eq 1 ]; then | ||
# Checking if subject exceeds 50 characters | ||
if [ $length -gt 50 ]; then | ||
echo -e "\e[31m*** Subject line exceeds 50 characters ***\e[0m"; | ||
exit 1 | ||
fi | ||
i=$(($length-1)) | ||
last_char=${line:$i:1} | ||
# Last character must not have a punctuation | ||
if [[ ! $last_char =~ [0-9a-zA-Z] ]]; then | ||
echo -e "\e[31m*** Last character of subject line must not contain punctuation ***\e[0m"; | ||
exit 1 | ||
fi | ||
elif [ $cnt -eq 2 ]; then | ||
# Subject must be followed by a blank line | ||
if [ $length -ne 0 ]; then | ||
echo -e "\e[31m*** Current subject line follows a non-empty line. Subject lines should always be followed by a blank line ***\e[0m"; | ||
exit 1 | ||
fi | ||
else | ||
# Any line in body must not exceed 72 characters | ||
if [ $length -gt 72 ]; then | ||
echo -e "\e[31m*** Line \"$line\" exceeds 72 characters ***\e[0m"; | ||
exit 1 | ||
fi | ||
fi | ||
done < "$1" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.