-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgxqs.sh
More file actions
executable file
·746 lines (624 loc) · 22.8 KB
/
gxqs.sh
File metadata and controls
executable file
·746 lines (624 loc) · 22.8 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
#!/usr/bin/env bash
#
# GXQS - Smart Merge Automation System
# Safely automates merging of multiple feature branches with parallel processing,
# retry mechanisms, and comprehensive reporting.
#
set -Eeuo pipefail
# ============================================================================
# CONFIGURATION
# ============================================================================
# Parallelism and timeout configuration
MAX_PARALLEL="${MAX_PARALLEL:-4}"
MAX_RETRIES="${MAX_RETRIES:-3}"
TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-900}"
# File paths
LOG_FILE="${LOG_FILE:-smart-merge.log}"
WORKTREE_ROOT="${WORKTREE_ROOT:-.worktrees}"
STATE_FILE="${STATE_FILE:-.merge-state}"
REPORT_FILE="${REPORT_FILE:-merge-report.json}"
# Slack webhook (optional)
SLACK_WEBHOOK="${SLACK_WEBHOOK:-}"
# Target branch for merging
TARGET_BRANCH="${TARGET_BRANCH:-dev}"
# Minimum merge score to accept (0-100)
MIN_MERGE_SCORE="${MIN_MERGE_SCORE:-60}"
# Command-line options
DRY_RUN=false
AUTO_SWEEP=false
# ============================================================================
# UTILITY FUNCTIONS
# ============================================================================
# Log with timestamp
log() {
local level="$1"
shift
local message="$*"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" >> "$LOG_FILE"
echo "[$timestamp] [$level] $message" >&2
}
# Run command with logging
run() {
local cmd="$*"
log "DEBUG" "Running: $cmd"
if [ "$DRY_RUN" = true ]; then
log "INFO" "DRY-RUN: Would execute: $cmd"
return 0
fi
eval "$cmd" 2>&1 | tee -a "$LOG_FILE"
return "${PIPESTATUS[0]}"
}
# Send Slack notification
notify_slack() {
local message="$1"
local level="${2:-info}"
if [ -z "$SLACK_WEBHOOK" ]; then
return 0
fi
local color="good"
case "$level" in
error) color="danger" ;;
warning) color="warning" ;;
esac
local payload
payload=$(cat <<EOF
{
"attachments": [{
"color": "$color",
"text": "$message",
"footer": "Smart Merge System",
"ts": $(date +%s)
}]
}
EOF
)
curl -X POST -H 'Content-type: application/json' \
--data "$payload" "$SLACK_WEBHOOK" 2>/dev/null || true
}
# Heartbeat monitoring
heartbeat() {
local branch="$1"
local status="$2"
log "HEARTBEAT" "Branch: $branch | Status: $status"
}
# Progress bar
progress_bar() {
local current="$1"
local total="$2"
local width=50
local percentage=$((current * 100 / total))
local filled=$((width * current / total))
local empty=$((width - filled))
printf "\r["
printf "%${filled}s" | tr ' ' '='
printf "%${empty}s" | tr ' ' ' '
printf "] %3d%% (%d/%d)" "$percentage" "$current" "$total"
}
# Retry mechanism with exponential backoff
retry() {
local max_attempts="$1"
shift
local cmd="$*"
local attempt=1
local delay=2
while [ $attempt -le "$max_attempts" ]; do
log "DEBUG" "Attempt $attempt/$max_attempts: $cmd"
if eval "$cmd"; then
return 0
fi
if [ $attempt -lt "$max_attempts" ]; then
log "WARN" "Command failed, retrying in ${delay}s..."
sleep "$delay"
delay=$((delay * 2))
fi
attempt=$((attempt + 1))
done
log "ERROR" "Command failed after $max_attempts attempts: $cmd"
return 1
}
# Add entry to JSON report
json_add() {
local branch="$1"
local status="$2"
local score="${3:-0}"
local message="${4:-}"
local conflicts="${5:-0}"
local files_changed="${6:-0}"
local entry
entry=$(cat <<EOF
{
"branch": "$branch",
"status": "$status",
"score": $score,
"message": "$message",
"conflicts": $conflicts,
"files_changed": $files_changed,
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
)
# Initialize report file if it doesn't exist
if [ ! -f "$REPORT_FILE" ]; then
echo '{"merges":[]}' > "$REPORT_FILE"
fi
# Add entry to report
local temp_file
temp_file=$(mktemp)
jq ".merges += [$entry]" "$REPORT_FILE" > "$temp_file" && mv "$temp_file" "$REPORT_FILE"
}
# Calculate merge score (0-100)
merge_score() {
local branch="$1"
local worktree_path="$2"
# Perform test merge to assess conflicts
cd "$worktree_path" || return 1
# Get merge statistics
local conflicts=0
local files_changed=0
local insertions=0
local deletions=0
# Attempt merge in test mode (without committing)
# Note: We use --no-commit to analyze the merge without completing it
if git merge --no-commit "$branch" 2>/dev/null; then
# Successful merge (or merge in progress), analyze changes
files_changed=$(git diff --cached --numstat | grep -vc "^-")
insertions=$(git diff --cached --numstat | grep -v "^-" | awk '{sum+=$1} END {print sum+0}')
deletions=$(git diff --cached --numstat | grep -v "^-" | awk '{sum+=$2} END {print sum+0}')
# Abort the test merge
git merge --abort 2>/dev/null || true
else
# Merge has conflicts
conflicts=$(git diff --name-only --diff-filter=U | wc -l)
files_changed=$(git diff --name-only | wc -l)
# Abort the test merge
git merge --abort 2>/dev/null || true
fi
# Calculate score based on factors
local score=100
# Deduct points for conflicts (10 points per conflict, max 50 points)
if [ "$conflicts" -gt 0 ]; then
local conflict_penalty=$((conflicts * 10))
[ "$conflict_penalty" -gt 50 ] && conflict_penalty=50
score=$((score - conflict_penalty))
fi
# Deduct points for large changes (0.1 points per file, max 20 points)
if [ "$files_changed" -gt 0 ]; then
local file_penalty=$((files_changed / 10))
[ "$file_penalty" -gt 20 ] && file_penalty=20
score=$((score - file_penalty))
fi
# Deduct points for massive code changes (max 30 points)
local total_changes=$((insertions + deletions))
if [ "$total_changes" -gt 1000 ]; then
local change_penalty=$(((total_changes - 1000) / 100))
[ "$change_penalty" -gt 30 ] && change_penalty=30
score=$((score - change_penalty))
fi
# Ensure score is not negative
[ "$score" -lt 0 ] && score=0
echo "$score:$conflicts:$files_changed"
}
# ============================================================================
# STATE MANAGEMENT
# ============================================================================
# Save state for resumability
save_state() {
local branch="$1"
local status="$2"
echo "$branch:$status:$(date +%s)" >> "$STATE_FILE"
}
# Load state
load_state() {
if [ -f "$STATE_FILE" ]; then
cat "$STATE_FILE"
fi
}
# Clear state
clear_state() {
rm -f "$STATE_FILE"
}
# ============================================================================
# BRANCH DISCOVERY
# ============================================================================
# Discover branches to merge
discover_branches() {
local branches=()
if [ "$AUTO_SWEEP" = true ]; then
log "INFO" "Auto-detecting feature branches..."
# Get all remote branches except main, dev, master
while IFS= read -r branch; do
# Remove 'origin/' prefix and trim whitespace
branch=$(echo "$branch" | sed 's/^[[:space:]]*origin\///' | tr -d '[:space:]')
# Skip if empty or matches excluded patterns
if [ -n "$branch" ] && [[ ! "$branch" =~ ^(main|dev|master|HEAD)$ ]]; then
branches+=("$branch")
fi
done < <(git branch -r | grep -v '\->' | grep '^[[:space:]]*origin/')
else
# Get branches from arguments
branches=("$@")
fi
# Output each branch on a new line
for branch in "${branches[@]}"; do
echo "$branch"
done
}
# ============================================================================
# WORKTREE MANAGEMENT
# ============================================================================
# Create worktree for branch
create_worktree() {
local branch="$1"
local worktree_path="$WORKTREE_ROOT/$branch"
# Clean up existing worktree if present
if [ -d "$worktree_path" ]; then
log "DEBUG" "Removing existing worktree: $worktree_path"
git worktree remove "$worktree_path" --force 2>/dev/null || true
rm -rf "$worktree_path"
fi
# Create new worktree
log "DEBUG" "Creating worktree for $branch at $worktree_path"
mkdir -p "$WORKTREE_ROOT"
if ! git worktree add "$worktree_path" "$TARGET_BRANCH" 2>&1 | tee -a "$LOG_FILE"; then
log "ERROR" "Failed to create worktree for $branch"
return 1
fi
echo "$worktree_path"
}
# Cleanup worktree
cleanup_worktree() {
local worktree_path="$1"
if [ -d "$worktree_path" ]; then
log "DEBUG" "Cleaning up worktree: $worktree_path"
git worktree remove "$worktree_path" --force 2>/dev/null || true
rm -rf "$worktree_path"
fi
}
# ============================================================================
# MERGE WORKFLOW
# ============================================================================
# Execute merge for a single branch
merge_branch() {
local branch="$1"
local start_time
start_time=$(date +%s)
log "INFO" "========================================="
log "INFO" "Starting merge for branch: $branch"
log "INFO" "========================================="
heartbeat "$branch" "started"
# Create worktree
local worktree_path
if ! worktree_path=$(create_worktree "$branch"); then
json_add "$branch" "failed" 0 "Failed to create worktree"
save_state "$branch" "failed"
heartbeat "$branch" "failed"
return 1
fi
# Calculate merge score
log "INFO" "Calculating merge score for $branch..."
local score_result
if ! score_result=$(merge_score "$branch" "$worktree_path"); then
log "ERROR" "Failed to calculate merge score for $branch"
cleanup_worktree "$worktree_path"
json_add "$branch" "failed" 0 "Failed to calculate merge score"
save_state "$branch" "failed"
heartbeat "$branch" "failed"
return 1
fi
local score conflicts files_changed
IFS=':' read -r score conflicts files_changed <<< "$score_result"
log "INFO" "Merge score for $branch: $score (conflicts: $conflicts, files: $files_changed)"
# Check if score meets threshold
if [ "$score" -lt "$MIN_MERGE_SCORE" ]; then
log "WARN" "Merge score $score is below threshold $MIN_MERGE_SCORE, skipping $branch"
cleanup_worktree "$worktree_path"
json_add "$branch" "skipped" "$score" "Score below threshold" "$conflicts" "$files_changed"
save_state "$branch" "skipped"
heartbeat "$branch" "skipped"
notify_slack "⚠️ Branch \`$branch\` skipped (score: $score, threshold: $MIN_MERGE_SCORE)" "warning"
return 0
fi
# Perform actual merge
cd "$worktree_path" || return 1
log "INFO" "Fetching latest changes for $branch..."
if ! retry "$MAX_RETRIES" git fetch origin "$branch"; then
log "ERROR" "Failed to fetch $branch"
cleanup_worktree "$worktree_path"
json_add "$branch" "failed" "$score" "Failed to fetch" "$conflicts" "$files_changed"
save_state "$branch" "failed"
heartbeat "$branch" "failed"
return 1
fi
log "INFO" "Merging $branch into $TARGET_BRANCH..."
if [ "$DRY_RUN" = true ]; then
log "INFO" "DRY-RUN: Would merge $branch (score: $score)"
cleanup_worktree "$worktree_path"
json_add "$branch" "dry-run" "$score" "Dry run successful" "$conflicts" "$files_changed"
save_state "$branch" "dry-run"
heartbeat "$branch" "dry-run"
return 0
fi
# Perform merge with timeout
local merge_pid
(
git merge --no-ff --no-edit "origin/$branch" 2>&1 | tee -a "$LOG_FILE"
) &
merge_pid=$!
# Wait with timeout
local elapsed=0
while kill -0 "$merge_pid" 2>/dev/null; do
if [ "$elapsed" -ge "$TIMEOUT_SECONDS" ]; then
log "ERROR" "Merge timeout for $branch (${TIMEOUT_SECONDS}s)"
kill -9 "$merge_pid" 2>/dev/null || true
cleanup_worktree "$worktree_path"
json_add "$branch" "timeout" "$score" "Merge timeout" "$conflicts" "$files_changed"
save_state "$branch" "timeout"
heartbeat "$branch" "timeout"
return 1
fi
sleep 1
elapsed=$((elapsed + 1))
done
wait $merge_pid
local merge_status=$?
if [ $merge_status -ne 0 ]; then
log "ERROR" "Merge failed for $branch"
cleanup_worktree "$worktree_path"
json_add "$branch" "failed" "$score" "Merge conflicts or errors" "$conflicts" "$files_changed"
save_state "$branch" "failed"
heartbeat "$branch" "failed"
notify_slack "❌ Failed to merge branch \`$branch\`" "error"
return 1
fi
# Push merged changes
log "INFO" "Pushing merged changes..."
if ! retry "$MAX_RETRIES" git push origin "$TARGET_BRANCH"; then
log "ERROR" "Failed to push merged changes for $branch"
cleanup_worktree "$worktree_path"
json_add "$branch" "failed" "$score" "Failed to push" "$conflicts" "$files_changed"
save_state "$branch" "failed"
heartbeat "$branch" "failed"
notify_slack "❌ Failed to push merge for branch \`$branch\`" "error"
return 1
fi
# Delete remote branch
log "INFO" "Deleting remote branch $branch..."
if ! git push origin --delete "$branch" 2>&1 | tee -a "$LOG_FILE"; then
log "WARN" "Failed to delete remote branch $branch (may not exist)"
fi
# Cleanup worktree
cleanup_worktree "$worktree_path"
local end_time
end_time=$(date +%s)
local duration=$((end_time - start_time))
log "INFO" "Successfully merged $branch in ${duration}s"
json_add "$branch" "success" "$score" "Merged successfully" "$conflicts" "$files_changed"
save_state "$branch" "success"
heartbeat "$branch" "success"
notify_slack "✅ Successfully merged branch \`$branch\` (score: $score, duration: ${duration}s)"
return 0
}
# ============================================================================
# PARALLEL EXECUTION
# ============================================================================
# Process branches in parallel
parallel_merge() {
local branches=("$@")
local total=${#branches[@]}
local completed=0
local pids=()
local active=0
log "INFO" "Processing $total branches with max parallelism: $MAX_PARALLEL"
# Initialize report file
echo '{"merges":[],"summary":{"total":0,"success":0,"failed":0,"skipped":0,"start_time":"'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"}}' > "$REPORT_FILE"
for branch in "${branches[@]}"; do
# Wait if max parallel limit reached
while [ "$active" -ge "$MAX_PARALLEL" ]; do
# Check for completed processes
for i in "${!pids[@]}"; do
if ! kill -0 "${pids[$i]}" 2>/dev/null; then
wait "${pids[$i]}" 2>/dev/null || true
unset "pids[$i]"
active=$((active - 1))
completed=$((completed + 1))
progress_bar "$completed" "$total"
fi
done
sleep 1
done
# Start merge in background
merge_branch "$branch" &
pids+=($!)
active=$((active + 1))
done
# Wait for remaining processes
for pid in "${pids[@]}"; do
wait "$pid" 2>/dev/null || true
completed=$((completed + 1))
progress_bar "$completed" "$total"
done
echo "" # New line after progress bar
log "INFO" "All merges completed"
}
# ============================================================================
# CLEANUP AND REPORTING
# ============================================================================
# Cleanup function
cleanup() {
log "INFO" "Performing cleanup..."
# Remove all worktrees
if [ -d "$WORKTREE_ROOT" ]; then
for worktree in "$WORKTREE_ROOT"/*; do
if [ -d "$worktree" ]; then
cleanup_worktree "$worktree"
fi
done
rm -rf "$WORKTREE_ROOT"
fi
log "INFO" "Cleanup completed"
}
# Generate final report
generate_report() {
log "INFO" "Generating final report..."
if [ ! -f "$REPORT_FILE" ]; then
log "WARN" "No report file found"
return
fi
# Calculate summary
local total success failed skipped timeout dry_run
total=$(jq '.merges | length' "$REPORT_FILE")
success=$(jq '[.merges[] | select(.status=="success")] | length' "$REPORT_FILE")
failed=$(jq '[.merges[] | select(.status=="failed")] | length' "$REPORT_FILE")
skipped=$(jq '[.merges[] | select(.status=="skipped")] | length' "$REPORT_FILE")
timeout=$(jq '[.merges[] | select(.status=="timeout")] | length' "$REPORT_FILE")
dry_run=$(jq '[.merges[] | select(.status=="dry-run")] | length' "$REPORT_FILE")
# Update summary in report
local temp_file
temp_file=$(mktemp)
jq ".summary.total = $total | .summary.success = $success | .summary.failed = $failed | .summary.skipped = $skipped | .summary.timeout = $timeout | .summary.dry_run = $dry_run | .summary.end_time = \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"" "$REPORT_FILE" > "$temp_file" && mv "$temp_file" "$REPORT_FILE"
log "INFO" "========================================="
log "INFO" "MERGE SUMMARY"
log "INFO" "========================================="
log "INFO" "Total branches: $total"
log "INFO" "Successful: $success"
log "INFO" "Failed: $failed"
log "INFO" "Skipped: $skipped"
log "INFO" "Timeout: $timeout"
[ "$dry_run" -gt 0 ] && log "INFO" "Dry-run: $dry_run"
log "INFO" "========================================="
log "INFO" "Report saved to: $REPORT_FILE"
# Send summary to Slack
notify_slack "📊 Merge Summary: $success/$total successful, $failed failed, $skipped skipped"
}
# ============================================================================
# MAIN EXECUTION
# ============================================================================
# Parse command-line options
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
log "INFO" "Dry-run mode enabled"
shift
;;
--auto-sweep)
AUTO_SWEEP=true
log "INFO" "Auto-sweep mode enabled"
shift
;;
--parallel)
MAX_PARALLEL="$2"
log "INFO" "Max parallel set to: $MAX_PARALLEL"
shift 2
;;
--help|-h)
# Already handled in entry point, but skip here
shift
;;
*)
# Store branches in a global array
BRANCHES_TO_MERGE+=("$1")
shift
;;
esac
done
}
# Main function
main() {
# Set up trap for cleanup
trap cleanup EXIT INT TERM
# Check if git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
log "ERROR" "Not a git repository"
exit 1
fi
# Check for required commands
for cmd in git jq curl; do
if ! command -v "$cmd" &> /dev/null; then
log "ERROR" "Required command not found: $cmd"
exit 1
fi
done
# Initialize global branches array
BRANCHES_TO_MERGE=()
# Parse arguments (sets global flags and BRANCHES_TO_MERGE)
parse_args "$@"
# Now log configuration after flags are set
log "INFO" "========================================="
log "INFO" "GXQS - Smart Merge Automation System"
log "INFO" "========================================="
log "INFO" "Configuration:"
log "INFO" " Max Parallel: $MAX_PARALLEL"
log "INFO" " Max Retries: $MAX_RETRIES"
log "INFO" " Timeout: ${TIMEOUT_SECONDS}s"
log "INFO" " Target Branch: $TARGET_BRANCH"
log "INFO" " Min Merge Score: $MIN_MERGE_SCORE"
log "INFO" " Dry Run: $DRY_RUN"
log "INFO" " Auto Sweep: $AUTO_SWEEP"
log "INFO" "========================================="
# Discover branches
local branches=()
if [ "$AUTO_SWEEP" = true ] || [ ${#BRANCHES_TO_MERGE[@]} -eq 0 ]; then
mapfile -t branches < <(discover_branches "${BRANCHES_TO_MERGE[@]}")
else
branches=("${BRANCHES_TO_MERGE[@]}")
fi
if [ ${#branches[@]} -eq 0 ]; then
log "ERROR" "No branches to merge"
exit 1
fi
log "INFO" "Branches to merge: ${branches[*]}"
# Execute parallel merge
parallel_merge "${branches[@]}"
# Generate final report
generate_report
# Clear state on successful completion
if [ "$DRY_RUN" = false ]; then
clear_state
fi
log "INFO" "========================================="
log "INFO" "Merge automation completed"
log "INFO" "========================================="
}
# Entry point
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Handle help before starting main
for arg in "$@"; do
if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
cat <<'EOF'
GXQS - Smart Merge Automation System
Usage: gxqs.sh [OPTIONS] [BRANCHES...]
Options:
--dry-run Preview operations without executing
--auto-sweep Automatically detect and merge all feature branches
--parallel N Set maximum parallel merges (default: 4)
--help, -h Show this help message
Environment Variables:
MAX_PARALLEL Maximum concurrent merges (default: 4)
MAX_RETRIES Retry attempts for failed operations (default: 3)
TIMEOUT_SECONDS Timeout per branch in seconds (default: 900)
LOG_FILE Log file path (default: smart-merge.log)
WORKTREE_ROOT Worktree directory (default: .worktrees)
STATE_FILE State file for resume capability (default: .merge-state)
REPORT_FILE JSON report output (default: merge-report.json)
SLACK_WEBHOOK Slack webhook URL for notifications (optional)
TARGET_BRANCH Target branch for merging (default: dev)
MIN_MERGE_SCORE Minimum merge score to accept (default: 60)
Examples:
# Merge specific branches
gxqs.sh feature/branch1 feature/branch2
# Auto-detect and merge all feature branches
gxqs.sh --auto-sweep
# Dry-run with auto-sweep
gxqs.sh --dry-run --auto-sweep
# Merge with custom parallelism
gxqs.sh --parallel 8 feature/branch1 feature/branch2
EOF
exit 0
fi
done
main "$@"
fi