-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommit_convention.sh
More file actions
31 lines (23 loc) · 1 KB
/
commit_convention.sh
File metadata and controls
31 lines (23 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
prepare_commit_msg_path=".git/hooks/prepare-commit-msg"
# Content of the prepare-commit-msg file
prepare_commit_msg_content="#!/bin/bash
commit_msg_title=\$(head -n 1 \"\$1\")
commit_msg_body=\$(tail -n +2 \"\$1\")
# Regular expression pattern to match specific commit types at the beginning of the commit message
commit_type_regex=\"^(\\[(Add|Edit|Fix|Test|Delete|Doc)\\])\"
if [[ ! \$commit_msg_title =~ \$commit_type_regex ]]; then
red=\$(tput setaf 1)
reset=\$(tput sgr0)
echo -e \"\${red}Invalid commit type. Available commit types: [Add], [Edit], [Fix], [Test], [Delete], [Doc]\${reset}\"
exit 1
fi
"
if [ -f "$prepare_commit_msg_path" ]; then
rm "$prepare_commit_msg_path"
echo -e "$(tput setaf 1)Deleted existing prepare-commit-msg file$(tput sgr0)"
fi
# Create the prepare-commit-msg file
echo "$prepare_commit_msg_content" > "$prepare_commit_msg_path"
chmod +x "$prepare_commit_msg_path"
echo -e "$(tput setaf 2)prepare-commit-msg file has been added to .git/hooks folder.$(tput sgr0)"