Files
RDP-login-monitor/scripts/Push-Mirror.ps1
T

42 lines
1.1 KiB
PowerShell

# Push main to a mirror remote with host-specific doc URLs, without leaving URL churn on main.
# Usage: .\scripts\Push-Mirror.ps1 github|kalinamall|papatramp
param(
[Parameter(Mandatory = $true)]
[ValidateSet('github', 'kalinamall', 'papatramp')]
[string]$Target
)
$ErrorActionPreference = 'Stop'
$Root = Split-Path -Parent $PSScriptRoot
Set-Location $Root
$remote = switch ($Target) {
'github' { 'github' }
'kalinamall' { 'kalinamall' }
'papatramp' { 'papatramp' }
}
git remote get-url $remote 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "remote not configured: $remote"
}
if ((git status --porcelain)) {
throw 'working tree not clean; commit or stash first'
}
$before = (git rev-parse HEAD).Trim()
& "$PSScriptRoot\Rewrite-GitHostUrls.ps1" -Target $Target
if (-not (git status --porcelain)) {
Write-Output "no URL changes for $Target; pushing as-is"
git push $remote main
exit 0
}
git add -A
git commit -m "chore(docs): sync repository URLs for ${Target} mirror"
git push $remote main
git reset --hard $before
Write-Output "pushed $remote with ${Target} URLs; local main reset to $before"