-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-commit.sh
More file actions
executable file
·246 lines (204 loc) · 8.46 KB
/
quick-commit.sh
File metadata and controls
executable file
·246 lines (204 loc) · 8.46 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
# ============================================================================
# Quick Commit Script for SecStore
# Interactive helper for fast Git commits with Conventional Commits
# ============================================================================
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ============================================================================
# Check if we're in a Git repository
# ============================================================================
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo -e "${RED}❌ Error: Not a Git repository!${NC}"
exit 1
fi
# ============================================================================
# Show current status
# ============================================================================
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}🔍 Current Git Status${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
git status --short
# Check if there are any changes
if [ -z "$(git status --porcelain)" ]; then
echo ""
echo -e "${GREEN}✅ Working directory clean - nothing to commit!${NC}"
exit 0
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# ============================================================================
# Ask if user wants to stage all changes
# ============================================================================
echo -ne "${YELLOW}📦 Add all changes to staging area? [Y/n]: ${NC}"
read -n 1 -r REPLY
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
git add .
echo -e "${GREEN}✅ All changes staged${NC}"
echo ""
else
echo -e "${YELLOW}⚠️ Skipped staging. Use 'git add <file>' manually.${NC}"
echo ""
echo -ne "${YELLOW}Continue with commit? [y/N]: ${NC}"
read -n 1 -r REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}❌ Aborted${NC}"
exit 1
fi
fi
# ============================================================================
# Show what will be committed
# ============================================================================
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}📋 Files to be committed:${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
git diff --cached --name-status
if [ -z "$(git diff --cached)" ]; then
echo -e "${RED}❌ No files staged for commit!${NC}"
exit 1
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# ============================================================================
# Commit Type Selection
# ============================================================================
echo -e "${YELLOW}💬 Select commit type:${NC}"
echo ""
echo " 1) feat: ✨ New feature"
echo " 2) fix: 🐛 Bug fix"
echo " 3) docs: 📝 Documentation"
echo " 4) refactor: 🔄 Code refactoring"
echo " 5) test: 🧪 Tests"
echo " 6) chore: 🔧 Maintenance"
echo " 7) style: 💅 Code style"
echo " 8) perf: ⚡ Performance"
echo " 9) security: 🔒 Security"
echo " 10) breaking: ⚠️ Breaking change"
echo " 11) custom ✏️ Custom message (no prefix)"
echo ""
echo -ne "${YELLOW}Choose [1-11]: ${NC}"
read choice
case $choice in
1) PREFIX="feat" ;;
2) PREFIX="fix" ;;
3) PREFIX="docs" ;;
4) PREFIX="refactor" ;;
5) PREFIX="test" ;;
6) PREFIX="chore" ;;
7) PREFIX="style" ;;
8) PREFIX="perf" ;;
9) PREFIX="security" ;;
10) PREFIX="breaking" ;;
11) PREFIX="" ;;
*)
echo -e "${RED}❌ Invalid choice. Using 'feat' as default.${NC}"
PREFIX="feat"
;;
esac
# ============================================================================
# Get commit message
# ============================================================================
echo ""
if [ -n "$PREFIX" ]; then
echo -ne "${YELLOW}📝 Commit message: ${PREFIX}: ${NC}"
read MESSAGE
FULL_MESSAGE="${PREFIX}: ${MESSAGE}"
else
echo -ne "${YELLOW}📝 Commit message: ${NC}"
read MESSAGE
FULL_MESSAGE="${MESSAGE}"
fi
# Check if message is empty
if [ -z "$MESSAGE" ]; then
echo -e "${RED}❌ Commit message cannot be empty!${NC}"
exit 1
fi
# ============================================================================
# Optional: Add scope
# ============================================================================
echo ""
echo -ne "${YELLOW}🎯 Add scope? (e.g., auth, api, docs) [optional]: ${NC}"
read SCOPE
if [ -n "$SCOPE" ] && [ -n "$PREFIX" ]; then
FULL_MESSAGE="${PREFIX}(${SCOPE}): ${MESSAGE}"
fi
# ============================================================================
# Show final commit message
# ============================================================================
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}📄 Final commit message:${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${GREEN}\"${FULL_MESSAGE}\"${NC}"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# ============================================================================
# Confirm commit
# ============================================================================
echo -ne "${YELLOW}✅ Proceed with commit? [Y/n]: ${NC}"
read -n 1 -r REPLY
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo -e "${RED}❌ Commit aborted${NC}"
exit 1
fi
# ============================================================================
# Execute commit
# ============================================================================
echo ""
echo -e "${BLUE}🚀 Committing...${NC}"
if git commit -m "$FULL_MESSAGE"; then
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}✅ Commit successful!${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
# Check if CHANGELOG was updated
if git diff HEAD~1 HEAD --name-only | grep -q "Documentation/CHANGELOG.md"; then
echo -e "${GREEN}📋 CHANGELOG.md automatically updated${NC}"
fi
else
echo ""
echo -e "${RED}❌ Commit failed!${NC}"
exit 1
fi
# ============================================================================
# Optional: Push to remote
# ============================================================================
echo ""
echo -ne "${YELLOW}🌐 Push to remote? [y/N]: ${NC}"
read -n 1 -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Get current branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo ""
echo -e "${BLUE}🚀 Pushing to origin/${BRANCH}...${NC}"
if git push origin "$BRANCH"; then
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}✅ Successfully pushed to remote!${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
else
echo ""
echo -e "${RED}❌ Push failed!${NC}"
exit 1
fi
else
echo -e "${YELLOW}⚠️ Skipped push. Use 'git push' manually when ready.${NC}"
fi
echo ""
echo -e "${GREEN}🎉 All done!${NC}"
echo ""