Repository navigation
Expand file tree
/
Copy pathgit_commit.sh
More file actions
executable file
·150 lines (130 loc) · 3.92 KB
/
Copy pathgit_commit.sh
File metadata and controls
executable file
·150 lines (130 loc) · 3.92 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# git_commit.sh - Interactive conventional commit helper
# Demonstrates: ui_choose, ui_input, ui_write, ui_confirm, ui_format_emoji
# shellcheck disable=SC1091
set -u
############################
# SCRIPT CONFIGURATION
############################
# Resolve our location even when invoked through a symlink.
_SELF="$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || printf %s "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "$_SELF")"
# Source library
source "$SCRIPT_DIR/../funny_gums.sh"
############################
# COMMIT TYPES
# VS16 emojis (♻️, ⚙️) are now supported with proper width handling
############################
COMMIT_TYPES=(
"feat ✨ A new feature"
"fix 🐛 A bug fix"
"docs 📚 Documentation only changes"
"style 💎 Code style (formatting, semicolons, etc)"
"refactor $EMOJI_RECYCLE Code refactoring"
"perf ⚡ Performance improvement"
"test 🧪 Adding or updating tests"
"build 📦 Build system or dependencies"
"ci 🤖 CI/CD configuration"
"chore $EMOJI_CPU Other changes (maintenance)"
"revert ⏪ Revert a previous commit"
)
############################
# MAIN
############################
echo ""
ui_box "🔨 Conventional Commit Helper" \
"" \
"Create a well-formatted commit message following" \
"the Conventional Commits specification."
echo ""
# Check if we're in a git repo
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
ui_error "Not a git repository!"
exit 1
fi
# Check for staged changes
if git diff --cached --quiet; then
ui_warn "No staged changes found!"
echo ""
if ! ui_confirm "Continue anyway?"; then
exit 0
fi
fi
# Step 1: Select commit type
echo ""
ui_info "Step 1: Select commit type"
type_line=$(ui_choose_with_header "Choose commit type:" "${COMMIT_TYPES[@]}")
if [[ -z "$type_line" ]]; then
ui_info "Cancelled."
exit 0
fi
commit_type=$(echo "$type_line" | awk '{print $1}')
echo " Selected: ${GREEN}$commit_type${RESET}"
# Step 2: Enter scope (optional)
echo ""
ui_info "Step 2: Enter scope (optional, e.g., api, ui, core)"
scope=$(ui_input "component name (optional)")
if [[ -n "$scope" ]]; then
echo " Scope: ${GREEN}$scope${RESET}"
else
echo " Scope: ${DIM}(none)${RESET}"
fi
# Step 3: Enter short description
echo ""
ui_info "Step 3: Enter short description (max 50 chars)"
description=$(ui_input "short description of change")
if [[ -z "$description" ]]; then
ui_error "Description is required!"
exit 1
fi
echo " Description: ${GREEN}$description${RESET}"
# Step 4: Enter body (optional)
echo ""
ui_info "Step 4: Enter detailed body (optional, Ctrl+D to finish)"
if ui_confirm "Add detailed body?" --default=false; then
body=$(ui_write "Detailed explanation of the change...")
else
body=""
fi
# Step 5: Breaking change?
echo ""
breaking=""
if ui_confirm "Is this a BREAKING CHANGE?" --default=false; then
breaking=$(ui_input "Describe the breaking change")
fi
# Step 6: Issue reference (optional)
echo ""
ui_info "Step 6: Reference issues (optional)"
issues=$(ui_input "e.g., Closes #123, Fixes #456")
############################
# BUILD COMMIT MESSAGE
############################
# Header: type(scope): description
if [[ -n "$scope" ]]; then
header="${commit_type}(${scope}): ${description}"
else
header="${commit_type}: ${description}"
fi
# Full message
commit_msg="$header"
if [[ -n "$body" ]]; then
commit_msg+="\n\n$body"
fi
if [[ -n "$breaking" ]]; then
commit_msg+="\n\nBREAKING CHANGE: $breaking"
fi
if [[ -n "$issues" ]]; then
commit_msg+="\n\n$issues"
fi
############################
# PREVIEW AND CONFIRM
############################
echo ""
ui_box "📝 Commit Message Preview" "" "$(echo -e "$commit_msg")"
echo ""
if ui_confirm "Create this commit?"; then
echo -e "$commit_msg" | git commit -F -
ui_success "✅ Commit created successfully!"
else
ui_info "Commit cancelled."
fi