-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-msg
77 lines (71 loc) · 2.95 KB
/
commit-msg
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
message="$(cat "$1")"
commit_title=$(echo "$message" | head -n1)
if [ -z "$message" ]; then
echo "------------------------------------------"
echo "🚨 Empty commit message!"
echo "Please provide a meaningful commit message"
echo "-"
echo "For more information, check script in .husky/commit-msg"
echo "-"
exit 1
fi
if [ ${#commit_title} -gt 100 ]; then
echo "------------------------------------------"
echo "🚨 Too long commit title!"
echo "The commit title must not exceed 100 characters"
echo "-"
echo "Your commit message was:"
echo "$message"
echo "-"
echo "For more information, check script in .husky/commit-msg"
echo "-"
exit 1
fi
if [ ${#commit_title} -lt 5 ]; then
echo "------------------------------------------"
echo "🚨 Too short commit title!"
echo "The commit title must have at least 5 characters"
echo "-"
echo "Your title message was:"
echo "$message"
echo "-"
echo "For more information, check script in .husky/commit-msg"
echo "-"
exit 1
fi
# If it's a merge message and it does not start with :twisted_rightwards_arrows:
# then wee automatically add it
if echo "$commit_title" | grep -qE "^Merge";
then
echo "------------------------------------------"
echo "🚨 Missing :twisted_rightwards_arrows: emoji!"
echo "Merge commit messages must start with the :twisted_rightwards_arrows: emoji"
echo "We automatically added it for you"
echo "-"
echo "Your commit message was:"
echo "$message"
echo "-"
echo "For more information, check script in .husky/commit-msg"
echo "-"
echo ":twisted_rightwards_arrows: $message" > "$1"
exit 0
fi
requiredPattern="^:(art|zap|fire|bug|ambulance|sparkles|memo|rocket|lipstick|tada|white_check_mark|lock|closed_lock_with_key|bookmark|rotating_light|construction|green_heart|arrow_down|arrow_up|pushpin|construction_worker|chart_with_upwards_trend|recycle|heavy_plus_sign|heavy_minus_sign|wrench|hammer|globe_with_meridians|pencil2|poop|rewind|twisted_rightwards_arrows|package|alien|truck|page_facing_up|boom|bento|wheelchair|bulb|beers|speech_balloon|card_file_box|loud_sound|mute|busts_in_silhouette|children_crossing|building_construction|iphone|clown_face|egg|see_no_evil|camera_flash|alembic|mag|label|seedling|triangular_flag_on_post|goal_net|dizzy|wastebasket|passport_control|adhesive_bandage|monocle_face|coffin|test_tube|necktie|stethoscope|bricks|technologist|money_with_wings|thread|safety_vest): .+$"
if ! echo "$commit_title" | grep -qE "$requiredPattern";
then
echo "------------------------------------------"
echo "🚨 Wrong commit title!"
echo "The commit title must have this format:"
echo ":emoji: <message>"
echo "Allowed emojis with their meanings are available at https://gitmoji.dev/"
echo "Example: \":art: Improve the design\""
echo "-"
echo "Your commit message was:"
echo "$message"
echo "-"
echo "For more information, check script in .husky/commit-msg"
echo "-"
exit 1
fi