Files
CTO/setup-git-auto-merge.sh
ReachableCEO 04a410d8cf Implement Phase 2 enhancements: git-native integration, testing, and progress tracking
MAJOR ENHANCEMENTS DELIVERED:

 Point 2 - Integration Automation:
- Git-native auto-merge using post-commit hooks (preferred over workflows)
- Automatic INTEGRATION-WIP merging on every feature branch commit
- Conflict handling with graceful error messages
- No dependency on Gitea Actions or external runners

 Point 4 - Bootstrap Testing Framework:
- Comprehensive 8-test validation suite (test-bootstrap.sh)
- Tests template files, git setup, branch creation, placeholders
- Validates AI agent instructions and automation scripts
- Color-coded output with detailed failure diagnostics

 Point 5 - Progress Dashboard System:
- Real-time HTML dashboard generation (generate-progress-dashboard.sh)
- Metrics collection from git history and worklog files
- Visual health scoring and activity tracking
- Mobile-responsive design for CTO oversight

PLATFORM UPDATES:
- Updated mental model: Gitea-exclusive (GitHub/GitLab banned)
- Removed all non-Gitea references from scripts and docs
- Simplified automation to git-native approach (user preference)
- Added PLATFORM-REQUIREMENTS.md to document constraints

TODO TRACKING SYSTEM:
- Comprehensive TODO.md (human-readable) with Phase 2/3 roadmap
- TODO-LLM.md (AI-optimized) for quick reference
- Detailed implementation priorities and success metrics
- Complete enhancement backlog organization

RETROSPECTIVE DOCUMENTATION:
- RETROSPECTIVE.md (human) - Complete project analysis
- RETROSPECTIVE-LLM.md (AI) - Concise summary for agents
- Comprehensive review of entire conversation and deliverables
- Future enhancement roadmap with prioritized improvements

Ready for Phase 2 implementation with production-ready Phase 1 foundation.
2025-09-05 08:03:48 -05:00

187 lines
6.6 KiB
Bash
Executable File

#!/bin/bash
# CTO AI Delegation - Git-Native Auto-Merge Setup
# Uses git hooks for automatic merging to INTEGRATION-WIP
set -e
echo "🔧 CTO AI Delegation - Git-Native Auto-Merge Setup"
echo "================================================="
echo "Setting up automatic merging to INTEGRATION-WIP using git hooks"
# Validate we're in a git repository
if [ ! -d ".git" ]; then
echo "❌ Error: Not in a git repository"
echo "🔧 Run this from your project root directory"
exit 1
fi
# Check if INTEGRATION-WIP branch exists
if ! git show-ref --quiet refs/heads/INTEGRATION-WIP; then
echo "❌ Error: INTEGRATION-WIP branch not found!"
echo "🔧 Run the bootstrap process first from docs/AGENT-LLM.MD"
exit 1
fi
# Create hooks directory if it doesn't exist
mkdir -p .git/hooks
echo "🔧 Setting up git hooks for automatic integration..."
# Create post-commit hook for auto-merge to INTEGRATION-WIP
cat > .git/hooks/post-commit << 'EOF'
#!/bin/bash
# CTO AI Delegation - Auto-merge to INTEGRATION-WIP
# Runs after every commit on feature branches or bootstrap
CURRENT_BRANCH=$(git branch --show-current)
# Only auto-merge from feature branches and bootstrap
if [[ "$CURRENT_BRANCH" == feature/* ]] || [[ "$CURRENT_BRANCH" == "bootstrap" ]]; then
echo "🔄 Auto-merging $CURRENT_BRANCH to INTEGRATION-WIP..."
# Save current branch
ORIGINAL_BRANCH="$CURRENT_BRANCH"
# Switch to INTEGRATION-WIP and merge
if git checkout INTEGRATION-WIP 2>/dev/null; then
if git merge "$ORIGINAL_BRANCH" --no-ff -m "🔄 Auto-Integration: $ORIGINAL_BRANCH → INTEGRATION-WIP
Branch: $ORIGINAL_BRANCH
Commit: $(git rev-parse HEAD)
Timestamp: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
🤖 CTO AI Delegation Framework - Git-Native Auto-Merge"; then
echo "✅ Successfully auto-merged $ORIGINAL_BRANCH to INTEGRATION-WIP"
# Switch back to original branch
git checkout "$ORIGINAL_BRANCH"
else
echo "❌ Auto-merge failed due to conflicts"
echo "🚨 Manual resolution required:"
echo " 1. Resolve conflicts in INTEGRATION-WIP"
echo " 2. Complete the merge manually"
echo " 3. Return to your feature branch: git checkout $ORIGINAL_BRANCH"
# Abort the merge and return to original branch
git merge --abort 2>/dev/null || true
git checkout "$ORIGINAL_BRANCH" 2>/dev/null || true
fi
else
echo "❌ Could not switch to INTEGRATION-WIP branch"
fi
fi
EOF
# Make post-commit hook executable
chmod +x .git/hooks/post-commit
# Create post-merge hook to handle pulled changes
cat > .git/hooks/post-merge << 'EOF'
#!/bin/bash
# CTO AI Delegation - Post-merge auto-integration
# Handles integration after pull/merge operations
CURRENT_BRANCH=$(git branch --show-current)
# Only process feature branches and bootstrap
if [[ "$CURRENT_BRANCH" == feature/* ]] || [[ "$CURRENT_BRANCH" == "bootstrap" ]]; then
# Check if we're not already on INTEGRATION-WIP
if [[ "$CURRENT_BRANCH" != "INTEGRATION-WIP" ]]; then
echo "🔄 Post-merge: Updating INTEGRATION-WIP with $CURRENT_BRANCH changes..."
# Save current branch
ORIGINAL_BRANCH="$CURRENT_BRANCH"
# Auto-merge to INTEGRATION-WIP
if git checkout INTEGRATION-WIP 2>/dev/null; then
if git merge "$ORIGINAL_BRANCH" --no-ff -m "🔄 Post-Merge Integration: $ORIGINAL_BRANCH → INTEGRATION-WIP
Branch: $ORIGINAL_BRANCH
Trigger: Post-merge hook
Timestamp: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
🤖 CTO AI Delegation Framework - Git-Native Auto-Merge"; then
echo "✅ Successfully updated INTEGRATION-WIP with $ORIGINAL_BRANCH changes"
else
echo "⚠️ Integration conflicts detected - manual resolution may be needed"
git merge --abort 2>/dev/null || true
fi
# Return to original branch
git checkout "$ORIGINAL_BRANCH" 2>/dev/null || true
fi
fi
fi
EOF
# Make post-merge hook executable
chmod +x .git/hooks/post-merge
# Create a push hook to ensure INTEGRATION-WIP is also pushed
cat > .git/hooks/pre-push << 'EOF'
#!/bin/bash
# CTO AI Delegation - Ensure INTEGRATION-WIP is pushed
# Automatically push INTEGRATION-WIP when feature branches are pushed
CURRENT_BRANCH=$(git branch --show-current)
# If pushing a feature branch or bootstrap, also push INTEGRATION-WIP
if [[ "$CURRENT_BRANCH" == feature/* ]] || [[ "$CURRENT_BRANCH" == "bootstrap" ]]; then
# Check if INTEGRATION-WIP has unpushed commits
if git diff --quiet origin/INTEGRATION-WIP INTEGRATION-WIP 2>/dev/null; then
echo "📋 INTEGRATION-WIP is up to date"
else
echo "🔄 Auto-pushing updated INTEGRATION-WIP..."
git push origin INTEGRATION-WIP || {
echo "⚠️ Could not push INTEGRATION-WIP - may need manual push later"
}
fi
fi
EOF
# Make pre-push hook executable
chmod +x .git/hooks/pre-push
echo ""
echo "✅ Git-native auto-merge setup complete!"
echo ""
echo "📋 How it works:"
echo " 1. Every commit on feature branches or bootstrap automatically merges to INTEGRATION-WIP"
echo " 2. Conflicts are handled gracefully with clear error messages"
echo " 3. INTEGRATION-WIP is automatically pushed when you push feature branches"
echo " 4. No external workflows or runners required - pure git!"
echo ""
echo "🧪 Test the setup:"
echo " 1. Create a test commit on a feature branch"
echo " 2. Check INTEGRATION-WIP branch for the auto-merge"
echo " 3. Push your feature branch and verify INTEGRATION-WIP is also pushed"
echo ""
echo "🎯 Git-native integration automation ready!"
# Update AGENT-LLM.MD to reflect git-native approach
if grep -q "INTEGRATION AUTOMATION" docs/AGENT-LLM.MD; then
# Replace existing automation section
sed -i '/## INTEGRATION AUTOMATION/,/^##/{/^##/!d;}' docs/AGENT-LLM.MD
sed -i '/## INTEGRATION AUTOMATION/d' docs/AGENT-LLM.MD
fi
# Add updated integration info
cat >> docs/AGENT-LLM.MD << 'EOF'
## INTEGRATION AUTOMATION (GIT-NATIVE)
**Automatic process - no action required by AI agents:**
- Every commit on feature branches automatically merges to INTEGRATION-WIP
- Uses git hooks (no external workflows required)
- Conflicts handled gracefully with clear error messages
- INTEGRATION-WIP automatically pushed when feature branches are pushed
- Pure git-native solution - no Gitea Actions needed
EOF
echo ""
echo "✅ Updated docs/AGENT-LLM.MD with git-native integration info"
echo ""
echo "🚀 Ready for automatic git-native integration!"