File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,9 @@ chmod +x .git/hooks/commit-msg
6868ln -sf ../../scripts/pre-push.hook .git/hooks/pre-push || exit 1
6969chmod +x .git/hooks/pre-push
7070
71+ ln -sf ../../scripts/prepare-commit-msg.hook .git/hooks/prepare-commit-msg || exit 1
72+ chmod +x .git/hooks/prepare-commit-msg
73+
7174touch .git/hooks/applied || exit 1
7275
7376echo
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ COMMIT_MSG_FILE=" $1 "
4+
5+ # Only proceed if the commit message file is empty (ignoring comment or blank lines).
6+ if grep -qE ' ^[^[:space:]#]' " $COMMIT_MSG_FILE " ; then
7+ exit 0
8+ fi
9+
10+ # Define the inline message with commit guidelines.
11+ INLINE_MSG=$( cat << 'EOF '
12+ # 🎉Check the rules before writing commit messages.
13+ # https://cbea.ms/git-commit/
14+ #
15+ # Seven Rules for a Great Git Commit Message:
16+ # 1. Separate subject from body with a blank line
17+ # 2. Limit the subject line to 50 characters
18+ # 3. Capitalize the subject line
19+ # 4. Do not end the subject line with a period
20+ # 5. Use the imperative mood in the subject line
21+ # 6. Wrap the body at 72 characters
22+ # 7. Use the body to explain what and why vs. how
23+ #
24+ # You may modify this commit message.
25+ # To abort this commit, exit the editor without saving.
26+ EOF
27+ )
28+
29+ # Write the inline guidelines into the commit message file.
30+ echo > " $COMMIT_MSG_FILE "
31+ echo -e " $INLINE_MSG " >> " $COMMIT_MSG_FILE "
32+
33+ # Prompt the user to optionally abort the commit.
34+ read -rp " Do you want to abort this commit? (y/N): " answer
35+ if [[ " $answer " =~ ^[Yy]$ ]]; then
36+ echo " Commit aborted by user." >&2
37+ exit 1
38+ fi
39+
40+ exit 0
You can’t perform that action at this time.
0 commit comments