sync SVN
This commit is contained in:
115
Teste/roa_sync.ps1
Normal file
115
Teste/roa_sync.ps1
Normal file
@@ -0,0 +1,115 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sincronizare de inceput de sesiune pentru FLORA2ROA (flux SVN + git text FoxBin2Prg).
|
||||
|
||||
.DESCRIPTION
|
||||
Echivalentul local al lui COMUN\scripts\roa_sync.ps1: FLORA2ROA nu are folder COMUN, deci
|
||||
nu primeste scriptul partajat prin svn update. Pasii sunt aceiasi, minus repo-ul COMUN:
|
||||
|
||||
1. svn update pe radacina proiectului. Esec sau conflicte -> stop, exit nenul.
|
||||
2. git_sync.ps1 (D:\ROA\UTIL\foxbin2prg) improspateaza textele .??2 din arbore.
|
||||
Esec -> fara commit, exit nenul.
|
||||
3. Pe branch-ul main: comite "sync SVN r<REV>" daca sunt schimbari, apoi reconciliaza
|
||||
cu origin (ff-only sau rebase) si face push DOAR daca toate commit-urile ahead sunt
|
||||
commit-uri de sync. Un commit non-sync nepushed blocheaza push-ul automat.
|
||||
|
||||
SVN ramane sursa de adevar pentru binare; git urmareste textele .??2 si sursele .prg.
|
||||
Scriptul NU face niciun svn commit.
|
||||
|
||||
.PARAMETER ProjectRoot
|
||||
Radacina proiectului (implicit: folderul parinte al acestui script).
|
||||
|
||||
.PARAMETER GitOnly
|
||||
Sare peste svn update si regenerarea textelor: doar commit + reconciliere + push.
|
||||
|
||||
.EXAMPLE
|
||||
roa_sync.bat
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ProjectRoot,
|
||||
[switch]$GitOnly
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not $ProjectRoot) { $ProjectRoot = Split-Path $PSScriptRoot -Parent }
|
||||
$ProjectRoot = (Resolve-Path $ProjectRoot).Path
|
||||
if (-not (Test-Path (Join-Path $ProjectRoot '.git'))) { Write-Host "EROARE: $ProjectRoot nu are .git"; exit 1 }
|
||||
|
||||
$avertismente = @()
|
||||
$rev = ''
|
||||
|
||||
if (-not $GitOnly) {
|
||||
Write-Host '=== 1. svn update ===' -ForegroundColor Cyan
|
||||
& svn update $ProjectRoot
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host 'EROARE: svn update a esuat.'; exit 1 }
|
||||
$conflicte = & svn status $ProjectRoot | Where-Object { $_ -match '^C|^!C|^\s*C' }
|
||||
if ($conflicte) { Write-Host 'EROARE: conflicte SVN nerezolvate:'; $conflicte; exit 1 }
|
||||
$rev = (& svn info $ProjectRoot | Select-String '^Revision:').Line -replace '[^0-9]', ''
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '=== 2. git_sync: regenerez textele .??2 ===' -ForegroundColor Cyan
|
||||
& 'D:\ROA\UTIL\foxbin2prg\git_sync.ps1' -ProjectRoot $ProjectRoot -DbfList @()
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host 'EROARE: git_sync a esuat; nu comit nimic.'; exit 1 }
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '=== 3. git: commit de sync + reconciliere cu origin ===' -ForegroundColor Cyan
|
||||
$branch = & git -C $ProjectRoot rev-parse --abbrev-ref HEAD
|
||||
if ($branch -ne 'main') {
|
||||
$avertismente += "branch curent = $branch (nu main): sar peste commit-ul de sync"
|
||||
} else {
|
||||
& git -C $ProjectRoot add -A
|
||||
$schimbari = & git -C $ProjectRoot status --porcelain
|
||||
if ($schimbari) {
|
||||
$msg = if ($rev) { "sync SVN r$rev" } else { 'sync SVN' }
|
||||
& git -C $ProjectRoot commit -q -m $msg
|
||||
Write-Host " commit: $msg"
|
||||
} else {
|
||||
Write-Host ' nimic de comis'
|
||||
}
|
||||
}
|
||||
|
||||
# reconciliere + push conditionat: doar commit-urile de sync se publica automat
|
||||
& git -C $ProjectRoot remote get-url origin *> $null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
$avertismente += 'fara remote origin: repo doar local (creeaza-l in gitea si adauga remote-ul)'
|
||||
} else {
|
||||
& git -C $ProjectRoot fetch origin 2>&1 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
$avertismente += 'fetch esuat (offline?): raman doar commit-uri locale'
|
||||
} elseif ($branch -eq 'main') {
|
||||
$ahead = @(& git -C $ProjectRoot log --format='%s' origin/main..main 2>$null)
|
||||
$behind = @(& git -C $ProjectRoot log --format='%h' main..origin/main 2>$null)
|
||||
if ($behind.Count -gt 0 -and $ahead.Count -eq 0) {
|
||||
& git -C $ProjectRoot merge --ff-only origin/main
|
||||
} elseif ($behind.Count -gt 0) {
|
||||
& git -C $ProjectRoot rebase origin/main
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
& git -C $ProjectRoot rebase --abort
|
||||
$avertismente += 'conflict real la rebase cu origin/main: rezolva manual'
|
||||
}
|
||||
}
|
||||
$ahead = @(& git -C $ProjectRoot log --format='%s' origin/main..main 2>$null)
|
||||
$nonSync = @($ahead | Where-Object { $_ -notmatch '^sync SVN' })
|
||||
if ($ahead.Count -eq 0) {
|
||||
Write-Host ' origin/main la zi'
|
||||
} elseif ($nonSync.Count -gt 0) {
|
||||
$avertismente += "push sarit: {0} commit(uri) non-sync nepushed (push manual dupa review)" -f $nonSync.Count
|
||||
} else {
|
||||
& git -C $ProjectRoot push origin main
|
||||
if ($LASTEXITCODE -ne 0) { $avertismente += 'push respins: se reconciliaza la urmatoarea rulare' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host '=== SUMAR ===' -ForegroundColor Cyan
|
||||
Write-Host ("revizie SVN : {0}" -f $(if ($rev) { $rev } else { '(sarit)' }))
|
||||
Write-Host ("branch git : {0}" -f $branch)
|
||||
Write-Host ("HEAD : {0}" -f (& git -C $ProjectRoot log --oneline -1))
|
||||
if ($avertismente) {
|
||||
Write-Host ''
|
||||
foreach ($a in $avertismente) { Write-Warning $a }
|
||||
}
|
||||
exit 0
|
||||
5
roa_sync.bat
Normal file
5
roa_sync.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
rem roa_sync.bat - sincronizare de inceput de sesiune pentru FLORA2ROA.
|
||||
rem Proiectul NU are folder COMUN (foloseste doar comun.h propriu), deci nu poate rula
|
||||
rem COMUN\scripts\roa_sync.ps1 ca celelalte proiecte ROA; apeleaza direct echivalentul local.
|
||||
powershell -ExecutionPolicy Bypass -File "%~dp0Teste\roa_sync.ps1" -ProjectRoot "%~dp0."
|
||||
Reference in New Issue
Block a user