# Submodule Auto-Sync Setup Script Write-Host "=== Setting up Submodule Auto-Sync ===" -ForegroundColor Cyan # 1. Initialize submodules Write-Host "`n[1/4] Initializing submodules..." -ForegroundColor Green git submodule update --init --recursive --remote --merge # 2. Configure Git Write-Host "`n[2/4] Configuring Git..." -ForegroundColor Green git config submodule.recurse false # 3. Create hook content $hookScript = "#!/bin/sh`n" $hookScript += "echo 'Auto-updating submodule to latest...'`n" $hookScript += "git submodule update --init --remote --merge`n`n" $hookScript += "if ! git diff-index --quiet HEAD -- Assets/Design_SubModule 2>/dev/null; then`n" $hookScript += " echo ''`n" $hookScript += " echo 'Submodule updated! To commit:'`n" $hookScript += " echo ' git add Assets/Design_SubModule'`n" $hookScript += " echo ' git commit -m Update_submodule'`n" $hookScript += " echo ' git push'`n" $hookScript += " echo ''`n" $hookScript += "fi`n" # 4. Install multiple hooks to cover all pull scenarios Write-Host "`n[3/4] Installing Git hooks..." -ForegroundColor Green # post-merge: triggers after git pull (when there's a merge) $hookScript | Out-File -FilePath ".git/hooks/post-merge" -Encoding ASCII -NoNewline Write-Host " - Installed post-merge hook" -ForegroundColor Gray # post-checkout: triggers after git pull (when fast-forward) $hookScript | Out-File -FilePath ".git/hooks/post-checkout" -Encoding ASCII -NoNewline Write-Host " - Installed post-checkout hook" -ForegroundColor Gray # post-rewrite: triggers after git pull --rebase $hookScript | Out-File -FilePath ".git/hooks/post-rewrite" -Encoding ASCII -NoNewline Write-Host " - Installed post-rewrite hook" -ForegroundColor Gray # 5. Create git sync alias as backup Write-Host "`n[4/4] Creating 'git sync' alias (backup method)..." -ForegroundColor Green git config alias.sync "!git pull && git submodule update --init --remote --merge" Write-Host "`n========================================" -ForegroundColor Cyan Write-Host "Setup complete!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "`nNow every 'git pull' will automatically update submodules!" -ForegroundColor Yellow Write-Host "`nUsage:" -ForegroundColor Cyan Write-Host " git pull <- Automatically updates submodules" -ForegroundColor White Write-Host " git sync <- Also available as backup" -ForegroundColor Gray Write-Host "`nTest it: Run 'git pull' now" -ForegroundColor Yellow