
#!/bin/bash
set -e

# ODGS Public Sync Script
# Safely pushes only the "Sovereign Standard" to the public repo.

echo "🛡️  Initiating Public Repo Sync (Sovereign Edition)..."

# 1. Check if we are in a clean state
if [[ -n $(git status -s) ]]; then
    echo "❌ Error: Working directory not clean. Commit or stash changes first."
    exit 1
fi

CURRENT_BRANCH=$(git branch --show-current)
PUBLIC_BRANCH="release/public-v3.3"

echo "   Current Branch: $CURRENT_BRANCH"
echo "   Target Branch:  $PUBLIC_BRANCH"

# 2. Create/Reset Public Branch from current state
if git show-ref --verify --quiet refs/heads/$PUBLIC_BRANCH; then
    git branch -D $PUBLIC_BRANCH
fi
git checkout -b $PUBLIC_BRANCH

echo "   ✂️  Pruning Private Assets..."

# 3. DELETE PRIVATE ASSETS (The UI, The AI, The Plans)
# We remove them from git index and filesystem for THIS branch only.

# Remove Private Source Code
git rm -rf src/odgs/ui || true
git rm -rf src/odgs/factory || true
git rm -rf src/odgs/registry || true

# Remove Private Docs
rm overall-plan.md || true
rm master-doc_commercial_strategy.md || true
rm architecture_audit_and_roadmap.md || true

# Remove Private Tests
rm tests/test_ui.py || true

# 4. COMMIT THE CLEAN STATE
git add .
git commit -m "Release v3.3.0: Sovereign Standard (Core Only)"

echo "   ✅ Public Branch Ready."
echo "   🚀 To Push: git push origin $PUBLIC_BRANCH:main --force"
echo "   (This overwrites 'main' on remote with this clean state)"

# 5. RETURN TO SAFETY
git checkout $CURRENT_BRANCH
echo "   🔙 Returned to $CURRENT_BRANCH (Private State Preserved)."
