<# .SYNOPSIS Sincronizare de inceput de sesiune pentru un proiect ROA (flux SVN + git text FoxBin2Prg). .DESCRIPTION Pasii: 1. svn update pe ProjectRoot (include externalul COMUN\). Esec / conflicte -> stop, exit nenul. 2. git_sync.ps1 -ProjectRoot (improspateaza textele .??2, inclusiv COMUN). Esec (exit nenul) -> avertizare, fara commit-uri de sync, exit nenul. 3. Repo proiect (ProjectRoot\.git): pe main comite "sync SVN r" daca sunt schimbari. Pe alt branch: avertizare si skip commit (nu schimba branch-ul daca are modificari necomise; daca working tree-ul e curat face checkout main). 4. La fel repo COMUN (ProjectRoot\COMUN\.git), cu revizia din svn info pe folderul COMUN. 5. Inchide branch-urile claude/* terminate (git diff main..branch gol) in ambele repo-uri. 6. Sumar final. .PARAMETER ProjectRoot Radacina proiectului. Implicit: directorul curent, daca are .git si un .pjx. #> [CmdletBinding()] param( [string]$ProjectRoot = '' ) $ErrorActionPreference = 'Stop' # --- deduce ProjectRoot din directorul curent daca nu e dat --- if (-not $ProjectRoot) { $cwd = (Get-Location).Path $hasGit = Test-Path -LiteralPath (Join-Path $cwd '.git') $hasPjx = @(Get-ChildItem -LiteralPath $cwd -Filter '*.pjx' -File -ErrorAction SilentlyContinue).Count -gt 0 if ($hasGit -and $hasPjx) { $ProjectRoot = $cwd } else { Write-Host "EROARE: -ProjectRoot nedat si directorul curent nu pare radacina de proiect ROA (lipseste .git sau .pjx): $cwd" exit 1 } } if (-not (Test-Path -LiteralPath $ProjectRoot -PathType Container)) { Write-Host "EROARE: ProjectRoot nu exista: $ProjectRoot" exit 1 } $ProjectRoot = (Get-Item -LiteralPath $ProjectRoot).FullName $comunRoot = Join-Path $ProjectRoot 'COMUN' $gitSync = Join-Path $PSScriptRoot 'git_sync.ps1' Write-Host "=== roa_sync: ProjectRoot=$ProjectRoot ===" # --- helper: revizia SVN a unui folder --- function Get-SvnRev([string]$path) { $rev = (& svn info --show-item revision $path 2>$null | Out-String).Trim() if ($LASTEXITCODE -ne 0 -or -not $rev) { return '' } return $rev } # =========================== 1. svn update =========================== Write-Host '' Write-Host "--- 1. svn update ---" $svnOut = & svn update $ProjectRoot $svnExit = $LASTEXITCODE $svnOut | ForEach-Object { Write-Host " $_" } if ($svnExit -ne 0) { Write-Host "EROARE: svn update a esuat (exit $svnExit). Ma opresc." exit 1 } # svn poate iesi 0 dar raporta conflicte in sumar if ($svnOut | Where-Object { $_ -match 'Summary of conflicts|conflict' }) { Write-Host "EROARE: svn update raporteaza conflicte. Rezolva-le manual, apoi reia. Ma opresc." exit 1 } $rev = Get-SvnRev $ProjectRoot Write-Host " Revizie SVN ProjectRoot: $(if($rev){$rev}else{'necunoscuta'})" # =========================== 2. git_sync =========================== Write-Host '' Write-Host "--- 2. git_sync (texte .??2) ---" if (-not (Test-Path -LiteralPath $gitSync)) { Write-Host "EROARE: nu gasesc git_sync.ps1 la $gitSync. Ma opresc." exit 1 } & powershell -ExecutionPolicy Bypass -NoProfile -File $gitSync -ProjectRoot $ProjectRoot $syncExit = $LASTEXITCODE if ($syncExit -ne 0) { Write-Host '' Write-Host "AVERTISMENT: git_sync a raportat esecuri (exit $syncExit). NU fac commit-uri de sync. Ma opresc." exit 1 } # =========================== 3-4. commit sync per repo =========================== # Sincronizeaza un repo git: pe main comite schimbarile ca "sync SVN r". # Intoarce: 'commit' / 'nimic' / 'skip-branch'. function Sync-Repo { param([string]$RepoDir, [string]$Rev, [string]$Label) if (-not (Test-Path -LiteralPath (Join-Path $RepoDir '.git'))) { Write-Host " ${Label}: fara repo git ($RepoDir) - sar peste." return 'nimic' } $branch = (& git -C $RepoDir rev-parse --abbrev-ref HEAD).Trim() if ($branch -ne 'main') { # tree curat = putem trece pe main; altfel nu atingem branch-ul $dirty = @(& git -C $RepoDir status --porcelain).Count -gt 0 if ($dirty) { Write-Host " ${Label}: esti pe '$branch'; sync-ul se face pe main. Ai modificari necomise - sar peste commit." return 'skip-branch' } Write-Host " ${Label}: pe '$branch' cu tree curat - fac checkout main." & git -C $RepoDir checkout main | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host " ${Label}: checkout main a esuat - sar peste commit." return 'skip-branch' } } & git -C $RepoDir add -A | Out-Null $staged = @(& git -C $RepoDir status --porcelain).Count -gt 0 if (-not $staged) { Write-Host " ${Label}: nimic de sincronizat." return 'nimic' } $msg = if ($Rev) { "sync SVN r$Rev" } else { "sync SVN" } & git -C $RepoDir commit -m $msg | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host " ${Label}: commit a esuat." return 'skip-branch' } Write-Host " ${Label}: commit '$msg'." return 'commit' } Write-Host '' Write-Host "--- 3. sync repo proiect ---" $resProj = Sync-Repo -RepoDir $ProjectRoot -Rev $rev -Label 'proiect' Write-Host '' Write-Host "--- 4. sync repo COMUN ---" $revComun = '' $resComun = 'nimic' if (Test-Path -LiteralPath $comunRoot -PathType Container) { $revComun = Get-SvnRev $comunRoot $resComun = Sync-Repo -RepoDir $comunRoot -Rev $revComun -Label 'COMUN' } else { Write-Host " COMUN: folderul nu exista ($comunRoot) - sar peste." } # =========================== 5. inchidere branch-uri claude/* =========================== # Inchide branch-urile claude/* al caror diff fata de main e gol (munca lor a intrat prin sync). function Close-ClaudeBranches { param([string]$RepoDir, [string]$Label) $closed = @(); $active = @() if (-not (Test-Path -LiteralPath (Join-Path $RepoDir '.git'))) { return @{ Closed=$closed; Active=$active } } $branches = @(& git -C $RepoDir for-each-ref --format='%(refname:short)' refs/heads/claude 2>$null) | Where-Object { $_ -and $_.Trim() } | ForEach-Object { $_.Trim() } foreach ($b in $branches) { $diff = @(& git -C $RepoDir diff --name-only main..$b 2>$null) | Where-Object { $_ -and $_.Trim() } if ($diff.Count -eq 0) { & git -C $RepoDir branch -D $b | Out-Null if ($LASTEXITCODE -eq 0) { $closed += $b; Write-Host " ${Label}: inchis $b" } else { Write-Host " ${Label}: nu am putut sterge $b" } } else { $active += $b Write-Host " ${Label}: activ $b ($($diff.Count) fisiere diferite)" } } return @{ Closed=$closed; Active=$active } } Write-Host '' Write-Host "--- 5. inchidere branch-uri claude/* ---" $brProj = Close-ClaudeBranches -RepoDir $ProjectRoot -Label 'proiect' $brComun = @{ Closed=@(); Active=@() } if (Test-Path -LiteralPath $comunRoot -PathType Container) { $brComun = Close-ClaudeBranches -RepoDir $comunRoot -Label 'COMUN' } # =========================== 6. sumar =========================== $commits = @() if ($resProj -eq 'commit') { $commits += "proiect: sync SVN r$rev" } if ($resComun -eq 'commit') { $commits += "COMUN: sync SVN r$revComun" } $closedAll = @($brProj.Closed + $brComun.Closed) $activeAll = @($brProj.Active + $brComun.Active) Write-Host '' Write-Host "===================== SUMAR =====================" Write-Host "Revizie SVN: proiect=$(if($rev){$rev}else{'?'})$(if($revComun){" COMUN=$revComun"})" if ($commits.Count -gt 0) { Write-Host "Commit-uri de sync:" $commits | ForEach-Object { Write-Host " $_" } } else { Write-Host "Commit-uri de sync: nimic de sincronizat" } Write-Host "Branch-uri inchise: $(if($closedAll.Count){$closedAll -join ', '}else{'niciunul'})" Write-Host "Branch-uri active: $(if($activeAll.Count){$activeAll -join ', '}else{'niciunul'})" Write-Host "================================================" exit 0