Files
shell-scripts/Windows/MigrateRemote.ps1
T

60 lines
1.8 KiB
PowerShell
Raw Normal View History

param (
[Parameter(Mandatory=$true)]
[string]$OldHost,
[Parameter(Mandatory=$true)]
[string]$NewHost
)
2026-06-19 17:57:55 +08:00
$ErrorActionPreference = "Stop"
$currentDir = Get-Item .
Write-Host "🚀 Scanning subdirectories under: $($currentDir.FullName)" -ForegroundColor Cyan
Write-Host " Old host: $OldHost → New host: $NewHost"
2026-06-19 17:57:55 +08:00
Write-Host "--------------------------------------------------"
$repoCount = 0
$updatedCount = 0
$subDirs = Get-ChildItem -Directory
foreach ($dir in $subDirs) {
Set-Location $dir.FullName
if (git rev-parse --is-inside-work-tree 2>$null) {
$repoCount++
$hasUpdates = $false
2026-06-19 17:57:55 +08:00
$remotes = git remote
2026-06-19 17:57:55 +08:00
foreach ($remote in $remotes) {
$currentUrl = git remote get-url $remote
if ($currentUrl -like "*$OldHost*") {
$newUrl = $currentUrl -replace [regex]::Escape($OldHost), $NewHost
2026-06-19 17:57:55 +08:00
if (-not $hasUpdates) {
Write-Host "📦 Git repository found: [$($dir.Name)]" -ForegroundColor Yellow
2026-06-19 17:57:55 +08:00
$hasUpdates = $true
}
Write-Host " ⚙️ Remote [$remote]:"
Write-Host " Old URL: $currentUrl"
Write-Host " New URL: $newUrl" -ForegroundColor Green
2026-06-19 17:57:55 +08:00
git remote set-url $remote $newUrl
}
}
2026-06-19 17:57:55 +08:00
if ($hasUpdates) {
Write-Host " ✅ Domain updated for this repository." -ForegroundColor Green
2026-06-19 17:57:55 +08:00
Write-Host "--------------------------------------------------"
$updatedCount++
}
}
}
Set-Location $currentDir.FullName
Write-Host "🏁 Scan complete." -ForegroundColor Cyan
Write-Host "📊 Summary: $repoCount Git repositories detected, $updatedCount updated with new domain." -ForegroundColor White