Skip to content

Commit a81e5df

Browse files
committed
added git commit-msg hook
1 parent 4735929 commit a81e5df

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.githooks/commit-msg

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# To activate this commit-msg hook, run the following commands from the main repository directory command shell:
4+
# chmod a+x .githooks/commit-msg # make executable
5+
# git config core.hooksPath ".githooks" # enable hook
6+
7+
# Public: Current API version in format "x.y.z".
8+
export API_VERSION="1.0.0"
9+
10+
#
11+
# Public: git commit-msg hook to reject multi-line commit messages.
12+
#
13+
# Checks whether git commit message is a single line or multiline and rejects multi-line commits.
14+
# git stores commit messages in a temporary file, .git/COMMIT_EDITMSG
15+
#
16+
# Exits with error code 1 if multi-line commit message found
17+
18+
reject_multiline_commit_messages() {
19+
# Read the commit message temporary file
20+
commit_message=$(cat .git/COMMIT_EDITMSG)
21+
22+
# Check if the commit message contains one or more line breaks
23+
if [[ "$commit_message" == *$'\n'* ]]; then
24+
echo "Multi-line commit messages are forbidden! Try committing again."
25+
exit 1
26+
fi
27+
}
28+
29+
reject_multiline_commit_messages # Exit with error if multi-line message found
30+
exit 0 # Proceed with commit otherwise

0 commit comments

Comments
 (0)