Files
git-mirror-zip/git-restore-zip.ps1
T

35 lines
757 B
PowerShell

param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$Zip,
[Parameter(Mandatory = $true, Position = 1)]
[string]$Target
)
$ErrorActionPreference = "Stop"
$WorkDir = ".tmp_restore_mirror"
if (-not (Test-Path $Zip)) {
Write-Host "Error: file not found: $Zip"
exit 1
}
try {
Write-Host "[1/3] Extracting $Zip ..."
New-Item -ItemType Directory -Force -Path $WorkDir | Out-Null
Expand-Archive -Path $Zip -DestinationPath $WorkDir -Force
Write-Host "[2/3] Pushing all refs to $Target ..."
Push-Location $WorkDir
git remote set-url origin $Target
git push --mirror
Pop-Location
Write-Host "[3/3] Done. Repository restored at $Target"
}
finally {
if (Test-Path $WorkDir) {
Remove-Item -Recurse -Force $WorkDir
}
}