feat(migrate-remote): accept hostname parameters

- Localised Chinese comments and strings to British English
- Removed step numbering from comments
- Old and new hostnames are now mandatory script parameters
This commit is contained in:
2026-06-23 13:57:29 +08:00
parent 0da76f102b
commit 8ab312ec39
+19 -20
View File
@@ -1,61 +1,60 @@
# 确保脚本在遇到非致命错误时也能正常处理
param (
[Parameter(Mandatory=$true)]
[string]$OldHost,
[Parameter(Mandatory=$true)]
[string]$NewHost
)
$ErrorActionPreference = "Stop"
$currentDir = Get-Item .
Write-Host "🚀 开始扫描当前目录下的子文件夹: $($currentDir.FullName)" -ForegroundColor Cyan
Write-Host "🚀 Scanning subdirectories under: $($currentDir.FullName)" -ForegroundColor Cyan
Write-Host " Old host: $OldHost → New host: $NewHost"
Write-Host "--------------------------------------------------"
$repoCount = 0
$updatedCount = 0
# 获取当前目录下的所有子文件夹
$subDirs = Get-ChildItem -Directory
foreach ($dir in $subDirs) {
# 切换到子文件夹路径
Set-Location $dir.FullName
# 1. 检测是否为 Git 仓库
if (git rev-parse --is-inside-work-tree 2>$null) {
$repoCount++
$hasUpdates = $false
# 2. 获取所有远程仓库名称
$remotes = git remote
foreach ($remote in $remotes) {
# 获取当前 remote 的 URL
$currentUrl = git remote get-url $remote
# 3. 检查并替换域名
if ($currentUrl -like "*git.onixbyte.com*") {
$newUrl = $currentUrl -replace "git.onixbyte.com", "onixbyte.dev"
if ($currentUrl -like "*$OldHost*") {
$newUrl = $currentUrl -replace [regex]::Escape($OldHost), $NewHost
# 首次发现匹配时,打印仓库名称
if (-not $hasUpdates) {
Write-Host "📦 发现 Git 仓库: [$($dir.Name)]" -ForegroundColor Yellow
Write-Host "📦 Git repository found: [$($dir.Name)]" -ForegroundColor Yellow
$hasUpdates = $true
}
Write-Host " ⚙️ 远程 [$remote]:"
Write-Host " 旧地址: $currentUrl"
Write-Host " 新地址: $newUrl" -ForegroundColor Green
Write-Host " ⚙️ Remote [$remote]:"
Write-Host " Old URL: $currentUrl"
Write-Host " New URL: $newUrl" -ForegroundColor Green
# 执行更新
git remote set-url $remote $newUrl
}
}
if ($hasUpdates) {
Write-Host "该仓库域名已更新完毕。" -ForegroundColor Green
Write-Host "Domain updated for this repository." -ForegroundColor Green
Write-Host "--------------------------------------------------"
$updatedCount++
}
}
}
# 恢复到初始执行路径
Set-Location $currentDir.FullName
Write-Host "🏁 扫描结束!" -ForegroundColor Cyan
Write-Host "📊 统计报告: 共检测了 $repoCount Git 仓库,其中 $updatedCount 个执行了域名更新。" -ForegroundColor White
Write-Host "🏁 Scan complete." -ForegroundColor Cyan
Write-Host "📊 Summary: $repoCount Git repositories detected, $updatedCount updated with new domain." -ForegroundColor White