myaidev-method 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/USER_GUIDE.md +630 -8
- package/bin/cli.js +161 -70
- package/package.json +1 -1
- package/src/lib/ascii-banner.js +100 -0
- package/src/templates/claude/commands/myai-deploy-dev.md +500 -0
- package/src/templates/claude/commands/myai-deploy-prod.md +837 -0
- package/src/templates/claude/commands/myai-deploy-staging.md +331 -0
- package/src/templates/claude/commands/myai-git-hotfix.md +957 -0
- package/src/templates/claude/commands/myai-git-pr.md +200 -0
- package/src/templates/claude/commands/myai-git-release.md +806 -0
- package/src/templates/claude/commands/myai-git-sync.md +796 -0
- package/src/templates/codex/commands/myai-astro-publish.md +51 -0
- package/src/templates/codex/commands/myai-configure.md +185 -0
- package/src/templates/codex/commands/myai-content-writer.md +73 -0
- package/src/templates/codex/commands/myai-coolify-deploy.md +159 -0
- package/src/templates/codex/commands/myai-deploy-dev.md +379 -0
- package/src/templates/codex/commands/myai-deploy-prod.md +431 -0
- package/src/templates/codex/commands/myai-deploy-staging.md +275 -0
- package/src/templates/codex/commands/myai-dev-architect.md +69 -0
- package/src/templates/codex/commands/myai-dev-code.md +82 -0
- package/src/templates/codex/commands/myai-dev-docs.md +83 -0
- package/src/templates/codex/commands/myai-dev-review.md +85 -0
- package/src/templates/codex/commands/myai-dev-test.md +84 -0
- package/src/templates/codex/commands/myai-docusaurus-publish.md +42 -0
- package/src/templates/codex/commands/myai-git-hotfix.md +512 -0
- package/src/templates/codex/commands/myai-git-pr.md +196 -0
- package/src/templates/codex/commands/myai-git-release.md +516 -0
- package/src/templates/codex/commands/myai-git-sync.md +517 -0
- package/src/templates/codex/commands/myai-mintlify-publish.md +42 -0
- package/src/templates/codex/commands/myai-payloadcms-publish.md +42 -0
- package/src/templates/codex/commands/myai-sparc-workflow.md +185 -0
- package/src/templates/codex/commands/myai-wordpress-admin.md +143 -0
- package/src/templates/codex/commands/myai-wordpress-publish.md +66 -0
- package/src/templates/gemini/commands/myai-astro-publish.toml +76 -0
- package/src/templates/gemini/commands/myai-configure.toml +188 -0
- package/src/templates/gemini/commands/myai-content-writer.toml +76 -0
- package/src/templates/gemini/commands/myai-coolify-deploy.toml +138 -0
- package/src/templates/gemini/commands/myai-deploy-dev.toml +379 -0
- package/src/templates/gemini/commands/myai-deploy-prod.toml +438 -0
- package/src/templates/gemini/commands/myai-deploy-staging.toml +275 -0
- package/src/templates/gemini/commands/myai-dev-architect.toml +64 -0
- package/src/templates/gemini/commands/myai-dev-code.toml +75 -0
- package/src/templates/gemini/commands/myai-dev-docs.toml +76 -0
- package/src/templates/gemini/commands/myai-dev-review.toml +78 -0
- package/src/templates/gemini/commands/myai-dev-test.toml +77 -0
- package/src/templates/gemini/commands/myai-docusaurus-publish.toml +63 -0
- package/src/templates/gemini/commands/myai-git-hotfix.toml +953 -0
- package/src/templates/gemini/commands/myai-git-pr.toml +196 -0
- package/src/templates/gemini/commands/myai-git-release.toml +802 -0
- package/src/templates/gemini/commands/myai-git-sync.toml +792 -0
- package/src/templates/gemini/commands/myai-mintlify-publish.toml +67 -0
- package/src/templates/gemini/commands/myai-payloadcms-publish.toml +59 -0
- package/src/templates/gemini/commands/myai-sparc-workflow.toml +47 -0
- package/src/templates/gemini/commands/myai-wordpress-admin.toml +143 -0
- package/src/templates/gemini/commands/myai-wordpress-publish.toml +77 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: myai-git-sync
|
|
3
|
+
description: Sync and manage branches across development workflow
|
|
4
|
+
tools: [bash, read, write]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You are a git workflow automation assistant specializing in branch synchronization and management.
|
|
8
|
+
|
|
9
|
+
Task: Sync branches and manage git workflow - $ARGUMENTS
|
|
10
|
+
|
|
11
|
+
## Branch Synchronization Workflow
|
|
12
|
+
|
|
13
|
+
### 1. Branch Status Overview
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
check_branch_status() {
|
|
17
|
+
echo "🔍 Checking branch status..."
|
|
18
|
+
|
|
19
|
+
# Current branch
|
|
20
|
+
current_branch=$(git branch --show-current)
|
|
21
|
+
echo "Current branch: $current_branch"
|
|
22
|
+
|
|
23
|
+
# Fetch latest from remote
|
|
24
|
+
git fetch --all --prune
|
|
25
|
+
|
|
26
|
+
# List all branches with status
|
|
27
|
+
echo ""
|
|
28
|
+
echo "╔══════════════════════════════════════════════════════════╗"
|
|
29
|
+
echo "║ BRANCH STATUS ║"
|
|
30
|
+
echo "╚══════════════════════════════════════════════════════════╝"
|
|
31
|
+
|
|
32
|
+
# Local branches
|
|
33
|
+
echo ""
|
|
34
|
+
echo "📍 Local Branches:"
|
|
35
|
+
git branch -vv
|
|
36
|
+
|
|
37
|
+
# Remote branches
|
|
38
|
+
echo ""
|
|
39
|
+
echo "☁️ Remote Branches:"
|
|
40
|
+
git branch -r
|
|
41
|
+
|
|
42
|
+
# Check for branches ahead/behind
|
|
43
|
+
echo ""
|
|
44
|
+
echo "📊 Sync Status:"
|
|
45
|
+
|
|
46
|
+
for branch in $(git branch --format='%(refname:short)'); do
|
|
47
|
+
if git rev-parse --verify "origin/$branch" &>/dev/null; then
|
|
48
|
+
ahead=$(git rev-list --count "origin/$branch..$branch" 2>/dev/null || echo "0")
|
|
49
|
+
behind=$(git rev-list --count "$branch..origin/$branch" 2>/dev/null || echo "0")
|
|
50
|
+
|
|
51
|
+
if [ "$ahead" -gt 0 ] || [ "$behind" -gt 0 ]; then
|
|
52
|
+
echo " $branch: ↑$ahead ↓$behind"
|
|
53
|
+
else
|
|
54
|
+
echo " $branch: ✅ synced"
|
|
55
|
+
fi
|
|
56
|
+
else
|
|
57
|
+
echo " $branch: ⚠️ not on remote"
|
|
58
|
+
fi
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
echo ""
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Show status
|
|
65
|
+
check_branch_status
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Sync Main/Master Branch
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
sync_main_branch() {
|
|
72
|
+
echo "🔄 Syncing main/master branch..."
|
|
73
|
+
|
|
74
|
+
# Determine main branch name
|
|
75
|
+
if git show-ref --verify --quiet refs/heads/main; then
|
|
76
|
+
main_branch="main"
|
|
77
|
+
elif git show-ref --verify --quiet refs/heads/master; then
|
|
78
|
+
main_branch="master"
|
|
79
|
+
else
|
|
80
|
+
echo "❌ No main/master branch found"
|
|
81
|
+
return 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
echo "Main branch: $main_branch"
|
|
85
|
+
|
|
86
|
+
# Save current branch
|
|
87
|
+
current_branch=$(git branch --show-current)
|
|
88
|
+
|
|
89
|
+
# Stash changes if any
|
|
90
|
+
if ! git diff-index --quiet HEAD --; then
|
|
91
|
+
echo "💾 Stashing local changes..."
|
|
92
|
+
git stash save "Auto-stash before sync $(date)"
|
|
93
|
+
stashed=true
|
|
94
|
+
else
|
|
95
|
+
stashed=false
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# Switch to main branch
|
|
99
|
+
git checkout "$main_branch" || {
|
|
100
|
+
echo "❌ Failed to checkout $main_branch"
|
|
101
|
+
return 1
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# Pull latest changes
|
|
105
|
+
echo "⬇️ Pulling latest changes..."
|
|
106
|
+
git pull origin "$main_branch" --rebase || {
|
|
107
|
+
echo "❌ Failed to pull changes"
|
|
108
|
+
git checkout "$current_branch"
|
|
109
|
+
return 1
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# Switch back to original branch
|
|
113
|
+
if [ "$current_branch" != "$main_branch" ]; then
|
|
114
|
+
git checkout "$current_branch"
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
# Restore stashed changes
|
|
118
|
+
if [ "$stashed" = true ]; then
|
|
119
|
+
echo "📂 Restoring stashed changes..."
|
|
120
|
+
git stash pop
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
echo "✅ Main branch synced"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
# Sync main
|
|
127
|
+
sync_main_branch
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 3. Sync Development Branch
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
sync_dev_branch() {
|
|
134
|
+
echo "🔄 Syncing development branch..."
|
|
135
|
+
|
|
136
|
+
# Determine dev branch name
|
|
137
|
+
if git show-ref --verify --quiet refs/heads/dev; then
|
|
138
|
+
dev_branch="dev"
|
|
139
|
+
elif git show-ref --verify --quiet refs/heads/develop; then
|
|
140
|
+
dev_branch="develop"
|
|
141
|
+
else
|
|
142
|
+
echo "⚠️ No dev/develop branch found"
|
|
143
|
+
return 0
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
echo "Dev branch: $dev_branch"
|
|
147
|
+
|
|
148
|
+
# Save current branch
|
|
149
|
+
current_branch=$(git branch --show-current)
|
|
150
|
+
|
|
151
|
+
# Switch to dev branch
|
|
152
|
+
git checkout "$dev_branch"
|
|
153
|
+
|
|
154
|
+
# Pull latest changes
|
|
155
|
+
echo "⬇️ Pulling latest changes..."
|
|
156
|
+
git pull origin "$dev_branch" --rebase || {
|
|
157
|
+
echo "❌ Failed to pull changes"
|
|
158
|
+
git checkout "$current_branch"
|
|
159
|
+
return 1
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# Merge main into dev (keep dev updated with main)
|
|
163
|
+
main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
|
|
164
|
+
|
|
165
|
+
echo "🔀 Merging $main_branch into $dev_branch..."
|
|
166
|
+
git merge "origin/$main_branch" --no-edit || {
|
|
167
|
+
echo "⚠️ Merge conflicts detected"
|
|
168
|
+
echo "Resolve conflicts and run: git merge --continue"
|
|
169
|
+
return 1
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
# Push updated dev branch
|
|
173
|
+
echo "⬆️ Pushing updated dev branch..."
|
|
174
|
+
git push origin "$dev_branch"
|
|
175
|
+
|
|
176
|
+
# Switch back to original branch
|
|
177
|
+
if [ "$current_branch" != "$dev_branch" ]; then
|
|
178
|
+
git checkout "$current_branch"
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
echo "✅ Dev branch synced"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
# Sync dev
|
|
185
|
+
sync_dev_branch
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 4. Sync Staging Branch
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
sync_staging_branch() {
|
|
192
|
+
echo "🔄 Syncing staging branch..."
|
|
193
|
+
|
|
194
|
+
if ! git show-ref --verify --quiet refs/heads/staging; then
|
|
195
|
+
echo "⚠️ No staging branch found"
|
|
196
|
+
return 0
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
# Save current branch
|
|
200
|
+
current_branch=$(git branch --show-current)
|
|
201
|
+
|
|
202
|
+
# Switch to staging
|
|
203
|
+
git checkout staging
|
|
204
|
+
|
|
205
|
+
# Pull latest changes
|
|
206
|
+
echo "⬇️ Pulling latest changes..."
|
|
207
|
+
git pull origin staging --rebase || {
|
|
208
|
+
echo "❌ Failed to pull changes"
|
|
209
|
+
git checkout "$current_branch"
|
|
210
|
+
return 1
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
# Merge dev into staging
|
|
214
|
+
dev_branch=$(git show-ref --verify --quiet refs/heads/dev && echo "dev" || echo "develop")
|
|
215
|
+
|
|
216
|
+
if git show-ref --verify --quiet "refs/heads/$dev_branch"; then
|
|
217
|
+
echo "🔀 Merging $dev_branch into staging..."
|
|
218
|
+
git merge "origin/$dev_branch" --no-edit || {
|
|
219
|
+
echo "⚠️ Merge conflicts detected"
|
|
220
|
+
return 1
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
# Push updated staging branch
|
|
224
|
+
echo "⬆️ Pushing updated staging branch..."
|
|
225
|
+
git push origin staging
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
# Switch back to original branch
|
|
229
|
+
if [ "$current_branch" != "staging" ]; then
|
|
230
|
+
git checkout "$current_branch"
|
|
231
|
+
fi
|
|
232
|
+
|
|
233
|
+
echo "✅ Staging branch synced"
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
# Sync staging
|
|
237
|
+
sync_staging_branch
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 5. Merge Main into Feature Branch
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
merge_main_into_feature() {
|
|
244
|
+
local feature_branch=${1:-$(git branch --show-current)}
|
|
245
|
+
|
|
246
|
+
echo "🔀 Merging main into feature branch: $feature_branch..."
|
|
247
|
+
|
|
248
|
+
# Ensure we're on the feature branch
|
|
249
|
+
if [ "$(git branch --show-current)" != "$feature_branch" ]; then
|
|
250
|
+
git checkout "$feature_branch" || {
|
|
251
|
+
echo "❌ Failed to checkout $feature_branch"
|
|
252
|
+
return 1
|
|
253
|
+
}
|
|
254
|
+
fi
|
|
255
|
+
|
|
256
|
+
# Determine main branch
|
|
257
|
+
main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
|
|
258
|
+
|
|
259
|
+
# Fetch latest
|
|
260
|
+
git fetch origin "$main_branch"
|
|
261
|
+
|
|
262
|
+
# Check if feature branch is behind main
|
|
263
|
+
behind=$(git rev-list --count "$feature_branch..origin/$main_branch")
|
|
264
|
+
|
|
265
|
+
if [ "$behind" -eq 0 ]; then
|
|
266
|
+
echo "✅ Feature branch is up to date with $main_branch"
|
|
267
|
+
return 0
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
echo "📊 Feature branch is $behind commits behind $main_branch"
|
|
271
|
+
|
|
272
|
+
# Stash changes if any
|
|
273
|
+
if ! git diff-index --quiet HEAD --; then
|
|
274
|
+
echo "💾 Stashing local changes..."
|
|
275
|
+
git stash save "Auto-stash before merge $(date)"
|
|
276
|
+
stashed=true
|
|
277
|
+
else
|
|
278
|
+
stashed=false
|
|
279
|
+
fi
|
|
280
|
+
|
|
281
|
+
# Merge main into feature
|
|
282
|
+
echo "🔀 Merging $main_branch..."
|
|
283
|
+
git merge "origin/$main_branch" --no-edit || {
|
|
284
|
+
echo "⚠️ Merge conflicts detected"
|
|
285
|
+
echo ""
|
|
286
|
+
echo "Conflicted files:"
|
|
287
|
+
git diff --name-only --diff-filter=U
|
|
288
|
+
echo ""
|
|
289
|
+
echo "Resolve conflicts then run:"
|
|
290
|
+
echo " git add <resolved-files>"
|
|
291
|
+
echo " git merge --continue"
|
|
292
|
+
|
|
293
|
+
if [ "$stashed" = true ]; then
|
|
294
|
+
echo " git stash pop"
|
|
295
|
+
fi
|
|
296
|
+
|
|
297
|
+
return 1
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
# Restore stashed changes
|
|
301
|
+
if [ "$stashed" = true ]; then
|
|
302
|
+
echo "📂 Restoring stashed changes..."
|
|
303
|
+
git stash pop
|
|
304
|
+
fi
|
|
305
|
+
|
|
306
|
+
# Push updated feature branch
|
|
307
|
+
read -p "Push updated feature branch? (yes/no): " push_confirm
|
|
308
|
+
|
|
309
|
+
if [ "$push_confirm" == "yes" ]; then
|
|
310
|
+
git push origin "$feature_branch"
|
|
311
|
+
echo "✅ Feature branch pushed"
|
|
312
|
+
fi
|
|
313
|
+
|
|
314
|
+
echo "✅ Main merged into feature branch"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
# Merge main into current branch
|
|
318
|
+
merge_main_into_feature
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### 6. Sync All Branches
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
sync_all_branches() {
|
|
325
|
+
echo "🔄 Syncing all branches..."
|
|
326
|
+
|
|
327
|
+
# Save current branch
|
|
328
|
+
current_branch=$(git branch --show-current)
|
|
329
|
+
|
|
330
|
+
# Fetch all
|
|
331
|
+
git fetch --all --prune
|
|
332
|
+
|
|
333
|
+
# Define branch hierarchy
|
|
334
|
+
main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
|
|
335
|
+
dev_branch=$(git show-ref --verify --quiet refs/heads/dev && echo "dev" || echo "develop")
|
|
336
|
+
|
|
337
|
+
# Sync main
|
|
338
|
+
echo ""
|
|
339
|
+
echo "═══════════════════════════════════════"
|
|
340
|
+
echo "Syncing $main_branch..."
|
|
341
|
+
echo "═══════════════════════════════════════"
|
|
342
|
+
git checkout "$main_branch"
|
|
343
|
+
git pull origin "$main_branch" --rebase
|
|
344
|
+
|
|
345
|
+
# Sync dev
|
|
346
|
+
if git show-ref --verify --quiet "refs/heads/$dev_branch"; then
|
|
347
|
+
echo ""
|
|
348
|
+
echo "═══════════════════════════════════════"
|
|
349
|
+
echo "Syncing $dev_branch..."
|
|
350
|
+
echo "═══════════════════════════════════════"
|
|
351
|
+
git checkout "$dev_branch"
|
|
352
|
+
git pull origin "$dev_branch" --rebase
|
|
353
|
+
git merge "origin/$main_branch" --no-edit
|
|
354
|
+
git push origin "$dev_branch"
|
|
355
|
+
fi
|
|
356
|
+
|
|
357
|
+
# Sync staging
|
|
358
|
+
if git show-ref --verify --quiet refs/heads/staging; then
|
|
359
|
+
echo ""
|
|
360
|
+
echo "═══════════════════════════════════════"
|
|
361
|
+
echo "Syncing staging..."
|
|
362
|
+
echo "═══════════════════════════════════════"
|
|
363
|
+
git checkout staging
|
|
364
|
+
git pull origin staging --rebase
|
|
365
|
+
if git show-ref --verify --quiet "refs/heads/$dev_branch"; then
|
|
366
|
+
git merge "origin/$dev_branch" --no-edit
|
|
367
|
+
else
|
|
368
|
+
git merge "origin/$main_branch" --no-edit
|
|
369
|
+
fi
|
|
370
|
+
git push origin staging
|
|
371
|
+
fi
|
|
372
|
+
|
|
373
|
+
# Return to original branch
|
|
374
|
+
git checkout "$current_branch"
|
|
375
|
+
|
|
376
|
+
echo ""
|
|
377
|
+
echo "✅ All branches synced"
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
# Uncomment to sync all branches
|
|
381
|
+
# sync_all_branches
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### 7. Clean Up Merged Branches
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
cleanup_merged_branches() {
|
|
388
|
+
echo "🧹 Cleaning up merged branches..."
|
|
389
|
+
|
|
390
|
+
# Determine main branch
|
|
391
|
+
main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
|
|
392
|
+
|
|
393
|
+
# Fetch and prune
|
|
394
|
+
git fetch --all --prune
|
|
395
|
+
|
|
396
|
+
# Find merged branches
|
|
397
|
+
echo "🔍 Finding merged branches..."
|
|
398
|
+
|
|
399
|
+
merged_branches=$(git branch --merged "$main_branch" | \
|
|
400
|
+
grep -v "^\*" | \
|
|
401
|
+
grep -v "$main_branch" | \
|
|
402
|
+
grep -v "develop" | \
|
|
403
|
+
grep -v "dev" | \
|
|
404
|
+
grep -v "staging" | \
|
|
405
|
+
grep -v "production")
|
|
406
|
+
|
|
407
|
+
if [ -z "$merged_branches" ]; then
|
|
408
|
+
echo "✅ No merged branches to clean up"
|
|
409
|
+
return 0
|
|
410
|
+
fi
|
|
411
|
+
|
|
412
|
+
echo "Branches merged into $main_branch:"
|
|
413
|
+
echo "$merged_branches"
|
|
414
|
+
echo ""
|
|
415
|
+
|
|
416
|
+
read -p "Delete these local branches? (yes/no): " delete_confirm
|
|
417
|
+
|
|
418
|
+
if [ "$delete_confirm" == "yes" ]; then
|
|
419
|
+
echo "$merged_branches" | xargs git branch -d
|
|
420
|
+
echo "✅ Local branches deleted"
|
|
421
|
+
fi
|
|
422
|
+
|
|
423
|
+
# Check remote branches
|
|
424
|
+
echo ""
|
|
425
|
+
echo "🔍 Checking remote merged branches..."
|
|
426
|
+
|
|
427
|
+
remote_merged=$(git branch -r --merged "$main_branch" | \
|
|
428
|
+
grep -v "HEAD" | \
|
|
429
|
+
grep -v "$main_branch" | \
|
|
430
|
+
grep -v "develop" | \
|
|
431
|
+
grep -v "dev" | \
|
|
432
|
+
grep -v "staging" | \
|
|
433
|
+
grep -v "production" | \
|
|
434
|
+
sed 's/origin\///')
|
|
435
|
+
|
|
436
|
+
if [ -z "$remote_merged" ]; then
|
|
437
|
+
echo "✅ No remote merged branches"
|
|
438
|
+
return 0
|
|
439
|
+
fi
|
|
440
|
+
|
|
441
|
+
echo "Remote branches merged into $main_branch:"
|
|
442
|
+
echo "$remote_merged"
|
|
443
|
+
echo ""
|
|
444
|
+
|
|
445
|
+
read -p "Delete these remote branches? (yes/no): " delete_remote
|
|
446
|
+
|
|
447
|
+
if [ "$delete_remote" == "yes" ]; then
|
|
448
|
+
echo "$remote_merged" | xargs -I {} git push origin --delete {}
|
|
449
|
+
echo "✅ Remote branches deleted"
|
|
450
|
+
fi
|
|
451
|
+
|
|
452
|
+
echo "✅ Branch cleanup complete"
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
# Cleanup merged branches
|
|
456
|
+
cleanup_merged_branches
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### 8. Handle Merge Conflicts
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
handle_merge_conflicts() {
|
|
463
|
+
echo "🔧 Merge conflict resolution helper..."
|
|
464
|
+
|
|
465
|
+
# Check if in merge state
|
|
466
|
+
if [ ! -f ".git/MERGE_HEAD" ]; then
|
|
467
|
+
echo "✅ No active merge conflicts"
|
|
468
|
+
return 0
|
|
469
|
+
fi
|
|
470
|
+
|
|
471
|
+
echo "⚠️ Active merge detected"
|
|
472
|
+
|
|
473
|
+
# Show conflicted files
|
|
474
|
+
echo ""
|
|
475
|
+
echo "📋 Conflicted files:"
|
|
476
|
+
git diff --name-only --diff-filter=U
|
|
477
|
+
|
|
478
|
+
echo ""
|
|
479
|
+
echo "Conflict resolution options:"
|
|
480
|
+
echo " 1. Use ours (keep current branch changes)"
|
|
481
|
+
echo " 2. Use theirs (accept incoming changes)"
|
|
482
|
+
echo " 3. Manual resolution"
|
|
483
|
+
echo " 4. Abort merge"
|
|
484
|
+
echo ""
|
|
485
|
+
|
|
486
|
+
read -p "Choose option (1-4): " option
|
|
487
|
+
|
|
488
|
+
case $option in
|
|
489
|
+
1)
|
|
490
|
+
echo "Accepting current branch changes..."
|
|
491
|
+
git diff --name-only --diff-filter=U | xargs git checkout --ours
|
|
492
|
+
git add -A
|
|
493
|
+
git merge --continue
|
|
494
|
+
;;
|
|
495
|
+
2)
|
|
496
|
+
echo "Accepting incoming changes..."
|
|
497
|
+
git diff --name-only --diff-filter=U | xargs git checkout --theirs
|
|
498
|
+
git add -A
|
|
499
|
+
git merge --continue
|
|
500
|
+
;;
|
|
501
|
+
3)
|
|
502
|
+
echo "Opening merge tool..."
|
|
503
|
+
git mergetool
|
|
504
|
+
;;
|
|
505
|
+
4)
|
|
506
|
+
echo "Aborting merge..."
|
|
507
|
+
git merge --abort
|
|
508
|
+
echo "✅ Merge aborted"
|
|
509
|
+
;;
|
|
510
|
+
*)
|
|
511
|
+
echo "Invalid option"
|
|
512
|
+
;;
|
|
513
|
+
esac
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
# Handle conflicts if present
|
|
517
|
+
handle_merge_conflicts
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### 9. Branch Comparison
|
|
521
|
+
|
|
522
|
+
```bash
|
|
523
|
+
compare_branches() {
|
|
524
|
+
local branch1=${1:-main}
|
|
525
|
+
local branch2=${2:-$(git branch --show-current)}
|
|
526
|
+
|
|
527
|
+
echo "🔍 Comparing branches: $branch1 vs $branch2"
|
|
528
|
+
|
|
529
|
+
# Fetch latest
|
|
530
|
+
git fetch origin
|
|
531
|
+
|
|
532
|
+
# Commits in branch2 not in branch1
|
|
533
|
+
echo ""
|
|
534
|
+
echo "📊 Commits in $branch2 not in $branch1:"
|
|
535
|
+
ahead_count=$(git rev-list --count "$branch1..$branch2")
|
|
536
|
+
echo "Total: $ahead_count commits"
|
|
537
|
+
if [ "$ahead_count" -gt 0 ]; then
|
|
538
|
+
git log --oneline "$branch1..$branch2"
|
|
539
|
+
fi
|
|
540
|
+
|
|
541
|
+
# Commits in branch1 not in branch2
|
|
542
|
+
echo ""
|
|
543
|
+
echo "📊 Commits in $branch1 not in $branch2:"
|
|
544
|
+
behind_count=$(git rev-list --count "$branch2..$branch1")
|
|
545
|
+
echo "Total: $behind_count commits"
|
|
546
|
+
if [ "$behind_count" -gt 0 ]; then
|
|
547
|
+
git log --oneline "$branch2..$branch1"
|
|
548
|
+
fi
|
|
549
|
+
|
|
550
|
+
# File differences
|
|
551
|
+
echo ""
|
|
552
|
+
echo "📁 File differences:"
|
|
553
|
+
git diff --stat "$branch1..$branch2"
|
|
554
|
+
|
|
555
|
+
# Summary
|
|
556
|
+
echo ""
|
|
557
|
+
echo "═══════════════════════════════════════"
|
|
558
|
+
echo "SUMMARY"
|
|
559
|
+
echo "═══════════════════════════════════════"
|
|
560
|
+
echo "$branch2 is:"
|
|
561
|
+
echo " ↑ $ahead_count commits ahead"
|
|
562
|
+
echo " ↓ $behind_count commits behind"
|
|
563
|
+
echo " of $branch1"
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
# Compare current branch with main
|
|
567
|
+
# compare_branches "main" "$(git branch --show-current)"
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
### 10. Pull Request Ready Check
|
|
571
|
+
|
|
572
|
+
```bash
|
|
573
|
+
pr_ready_check() {
|
|
574
|
+
local feature_branch=${1:-$(git branch --show-current)}
|
|
575
|
+
|
|
576
|
+
echo "✅ PR Ready Check: $feature_branch"
|
|
577
|
+
|
|
578
|
+
# Determine main branch
|
|
579
|
+
main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
|
|
580
|
+
|
|
581
|
+
# Fetch latest
|
|
582
|
+
git fetch origin
|
|
583
|
+
|
|
584
|
+
# Check 1: Branch is pushed
|
|
585
|
+
if ! git rev-parse --verify "origin/$feature_branch" &>/dev/null; then
|
|
586
|
+
echo "❌ Branch not pushed to remote"
|
|
587
|
+
echo " Run: git push origin $feature_branch"
|
|
588
|
+
return 1
|
|
589
|
+
fi
|
|
590
|
+
|
|
591
|
+
# Check 2: No uncommitted changes
|
|
592
|
+
if ! git diff-index --quiet HEAD --; then
|
|
593
|
+
echo "❌ Uncommitted changes detected"
|
|
594
|
+
git status --short
|
|
595
|
+
return 1
|
|
596
|
+
fi
|
|
597
|
+
|
|
598
|
+
# Check 3: Up to date with main
|
|
599
|
+
behind=$(git rev-list --count "$feature_branch..origin/$main_branch")
|
|
600
|
+
if [ "$behind" -gt 0 ]; then
|
|
601
|
+
echo "⚠️ Branch is $behind commits behind $main_branch"
|
|
602
|
+
echo " Consider merging main: /myai-git-sync merge-main"
|
|
603
|
+
fi
|
|
604
|
+
|
|
605
|
+
# Check 4: Conflicts with main
|
|
606
|
+
if ! git merge-tree "$(git merge-base $feature_branch origin/$main_branch)" "$feature_branch" "origin/$main_branch" | grep -q "^-"; then
|
|
607
|
+
echo "✅ No conflicts with $main_branch"
|
|
608
|
+
else
|
|
609
|
+
echo "⚠️ May have conflicts with $main_branch"
|
|
610
|
+
fi
|
|
611
|
+
|
|
612
|
+
# Check 5: Tests pass
|
|
613
|
+
echo "🧪 Running tests..."
|
|
614
|
+
if npm test &>/dev/null; then
|
|
615
|
+
echo "✅ Tests passing"
|
|
616
|
+
else
|
|
617
|
+
echo "❌ Tests failing"
|
|
618
|
+
return 1
|
|
619
|
+
fi
|
|
620
|
+
|
|
621
|
+
# Check 6: Linting
|
|
622
|
+
if command -v npm &>/dev/null && grep -q "\"lint\"" package.json 2>/dev/null; then
|
|
623
|
+
if npm run lint &>/dev/null; then
|
|
624
|
+
echo "✅ Linting passing"
|
|
625
|
+
else
|
|
626
|
+
echo "⚠️ Linting issues detected"
|
|
627
|
+
fi
|
|
628
|
+
fi
|
|
629
|
+
|
|
630
|
+
# Summary
|
|
631
|
+
echo ""
|
|
632
|
+
echo "═══════════════════════════════════════"
|
|
633
|
+
echo "✅ Ready to create Pull Request!"
|
|
634
|
+
echo "═══════════════════════════════════════"
|
|
635
|
+
|
|
636
|
+
# Generate PR creation command
|
|
637
|
+
if command -v gh &>/dev/null; then
|
|
638
|
+
echo ""
|
|
639
|
+
echo "Create PR with:"
|
|
640
|
+
echo " gh pr create --base $main_branch --head $feature_branch"
|
|
641
|
+
fi
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
# Check if ready for PR
|
|
645
|
+
pr_ready_check
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### 11. Sync Notification
|
|
649
|
+
|
|
650
|
+
```bash
|
|
651
|
+
send_sync_notification() {
|
|
652
|
+
local sync_summary=$1
|
|
653
|
+
|
|
654
|
+
# Slack notification
|
|
655
|
+
if [ -n "$SLACK_WEBHOOK_URL" ]; then
|
|
656
|
+
curl -X POST "$SLACK_WEBHOOK_URL" \
|
|
657
|
+
-H 'Content-Type: application/json' \
|
|
658
|
+
-d "{
|
|
659
|
+
\"text\": \"🔄 Branch Sync Complete\",
|
|
660
|
+
\"blocks\": [
|
|
661
|
+
{
|
|
662
|
+
\"type\": \"section\",
|
|
663
|
+
\"text\": {
|
|
664
|
+
\"type\": \"mrkdwn\",
|
|
665
|
+
\"text\": \"*Branch Synchronization*\n$sync_summary\"
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
]
|
|
669
|
+
}"
|
|
670
|
+
fi
|
|
671
|
+
|
|
672
|
+
# Discord notification
|
|
673
|
+
if [ -n "$DISCORD_WEBHOOK_URL" ]; then
|
|
674
|
+
curl -X POST "$DISCORD_WEBHOOK_URL" \
|
|
675
|
+
-H 'Content-Type: application/json' \
|
|
676
|
+
-d "{
|
|
677
|
+
\"content\": \"🔄 **Branch Sync Complete**\",
|
|
678
|
+
\"embeds\": [{
|
|
679
|
+
\"description\": \"$sync_summary\",
|
|
680
|
+
\"color\": 3447003
|
|
681
|
+
}]
|
|
682
|
+
}"
|
|
683
|
+
fi
|
|
684
|
+
}
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
## Complete Sync Script
|
|
688
|
+
|
|
689
|
+
```bash
|
|
690
|
+
#!/bin/bash
|
|
691
|
+
set -e
|
|
692
|
+
|
|
693
|
+
echo "🔄 Git Branch Synchronization"
|
|
694
|
+
echo "═══════════════════════════════════════"
|
|
695
|
+
|
|
696
|
+
# Parse arguments
|
|
697
|
+
action=${1:-status}
|
|
698
|
+
|
|
699
|
+
case $action in
|
|
700
|
+
status)
|
|
701
|
+
check_branch_status
|
|
702
|
+
;;
|
|
703
|
+
|
|
704
|
+
main)
|
|
705
|
+
sync_main_branch
|
|
706
|
+
;;
|
|
707
|
+
|
|
708
|
+
dev)
|
|
709
|
+
sync_dev_branch
|
|
710
|
+
;;
|
|
711
|
+
|
|
712
|
+
staging)
|
|
713
|
+
sync_staging_branch
|
|
714
|
+
;;
|
|
715
|
+
|
|
716
|
+
all)
|
|
717
|
+
sync_all_branches
|
|
718
|
+
;;
|
|
719
|
+
|
|
720
|
+
merge-main)
|
|
721
|
+
merge_main_into_feature
|
|
722
|
+
;;
|
|
723
|
+
|
|
724
|
+
cleanup)
|
|
725
|
+
cleanup_merged_branches
|
|
726
|
+
;;
|
|
727
|
+
|
|
728
|
+
compare)
|
|
729
|
+
compare_branches "$2" "$3"
|
|
730
|
+
;;
|
|
731
|
+
|
|
732
|
+
pr-check)
|
|
733
|
+
pr_ready_check "$2"
|
|
734
|
+
;;
|
|
735
|
+
|
|
736
|
+
conflicts)
|
|
737
|
+
handle_merge_conflicts
|
|
738
|
+
;;
|
|
739
|
+
|
|
740
|
+
*)
|
|
741
|
+
echo "Usage: /myai-git-sync [command]"
|
|
742
|
+
echo ""
|
|
743
|
+
echo "Commands:"
|
|
744
|
+
echo " status - Show branch status overview"
|
|
745
|
+
echo " main - Sync main/master branch"
|
|
746
|
+
echo " dev - Sync dev/develop branch"
|
|
747
|
+
echo " staging - Sync staging branch"
|
|
748
|
+
echo " all - Sync all branches"
|
|
749
|
+
echo " merge-main - Merge main into current feature branch"
|
|
750
|
+
echo " cleanup - Clean up merged branches"
|
|
751
|
+
echo " compare - Compare two branches"
|
|
752
|
+
echo " pr-check - Check if ready for pull request"
|
|
753
|
+
echo " conflicts - Handle merge conflicts"
|
|
754
|
+
;;
|
|
755
|
+
esac
|
|
756
|
+
|
|
757
|
+
echo ""
|
|
758
|
+
echo "✅ Sync operation complete"
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
## Quick Commands
|
|
762
|
+
|
|
763
|
+
```bash
|
|
764
|
+
# Check status
|
|
765
|
+
/myai-git-sync status
|
|
766
|
+
|
|
767
|
+
# Sync main branch
|
|
768
|
+
/myai-git-sync main
|
|
769
|
+
|
|
770
|
+
# Sync all branches
|
|
771
|
+
/myai-git-sync all
|
|
772
|
+
|
|
773
|
+
# Merge main into feature
|
|
774
|
+
/myai-git-sync merge-main
|
|
775
|
+
|
|
776
|
+
# Clean up merged branches
|
|
777
|
+
/myai-git-sync cleanup
|
|
778
|
+
|
|
779
|
+
# Check PR readiness
|
|
780
|
+
/myai-git-sync pr-check
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
## Environment Configuration
|
|
784
|
+
|
|
785
|
+
```bash
|
|
786
|
+
# Notifications (optional)
|
|
787
|
+
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK
|
|
788
|
+
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR/WEBHOOK
|
|
789
|
+
|
|
790
|
+
# Branch names (defaults)
|
|
791
|
+
MAIN_BRANCH=main
|
|
792
|
+
DEV_BRANCH=dev
|
|
793
|
+
STAGING_BRANCH=staging
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
Execute branch synchronization and management operations efficiently.
|