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:
+19
-20
@@ -1,61 +1,60 @@
|
|||||||
# 确保脚本在遇到非致命错误时也能正常处理
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$OldHost,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$NewHost
|
||||||
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
$currentDir = Get-Item .
|
$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 "--------------------------------------------------"
|
Write-Host "--------------------------------------------------"
|
||||||
|
|
||||||
$repoCount = 0
|
$repoCount = 0
|
||||||
$updatedCount = 0
|
$updatedCount = 0
|
||||||
|
|
||||||
# 获取当前目录下的所有子文件夹
|
|
||||||
$subDirs = Get-ChildItem -Directory
|
$subDirs = Get-ChildItem -Directory
|
||||||
|
|
||||||
foreach ($dir in $subDirs) {
|
foreach ($dir in $subDirs) {
|
||||||
# 切换到子文件夹路径
|
|
||||||
Set-Location $dir.FullName
|
Set-Location $dir.FullName
|
||||||
|
|
||||||
# 1. 检测是否为 Git 仓库
|
|
||||||
if (git rev-parse --is-inside-work-tree 2>$null) {
|
if (git rev-parse --is-inside-work-tree 2>$null) {
|
||||||
$repoCount++
|
$repoCount++
|
||||||
$hasUpdates = $false
|
$hasUpdates = $false
|
||||||
|
|
||||||
# 2. 获取所有远程仓库名称
|
|
||||||
$remotes = git remote
|
$remotes = git remote
|
||||||
|
|
||||||
foreach ($remote in $remotes) {
|
foreach ($remote in $remotes) {
|
||||||
# 获取当前 remote 的 URL
|
|
||||||
$currentUrl = git remote get-url $remote
|
$currentUrl = git remote get-url $remote
|
||||||
|
|
||||||
# 3. 检查并替换域名
|
if ($currentUrl -like "*$OldHost*") {
|
||||||
if ($currentUrl -like "*git.onixbyte.com*") {
|
$newUrl = $currentUrl -replace [regex]::Escape($OldHost), $NewHost
|
||||||
$newUrl = $currentUrl -replace "git.onixbyte.com", "onixbyte.dev"
|
|
||||||
|
|
||||||
# 首次发现匹配时,打印仓库名称
|
|
||||||
if (-not $hasUpdates) {
|
if (-not $hasUpdates) {
|
||||||
Write-Host "📦 发现 Git 仓库: [$($dir.Name)]" -ForegroundColor Yellow
|
Write-Host "📦 Git repository found: [$($dir.Name)]" -ForegroundColor Yellow
|
||||||
$hasUpdates = $true
|
$hasUpdates = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host " ⚙️ 远程 [$remote]:"
|
Write-Host " ⚙️ Remote [$remote]:"
|
||||||
Write-Host " 旧地址: $currentUrl"
|
Write-Host " Old URL: $currentUrl"
|
||||||
Write-Host " 新地址: $newUrl" -ForegroundColor Green
|
Write-Host " New URL: $newUrl" -ForegroundColor Green
|
||||||
|
|
||||||
# 执行更新
|
|
||||||
git remote set-url $remote $newUrl
|
git remote set-url $remote $newUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hasUpdates) {
|
if ($hasUpdates) {
|
||||||
Write-Host " ✅ 该仓库域名已更新完毕。" -ForegroundColor Green
|
Write-Host " ✅ Domain updated for this repository." -ForegroundColor Green
|
||||||
Write-Host "--------------------------------------------------"
|
Write-Host "--------------------------------------------------"
|
||||||
$updatedCount++
|
$updatedCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 恢复到初始执行路径
|
|
||||||
Set-Location $currentDir.FullName
|
Set-Location $currentDir.FullName
|
||||||
|
|
||||||
Write-Host "🏁 扫描结束!" -ForegroundColor Cyan
|
Write-Host "🏁 Scan complete." -ForegroundColor Cyan
|
||||||
Write-Host "📊 统计报告: 共检测了 $repoCount 个 Git 仓库,其中 $updatedCount 个执行了域名更新。" -ForegroundColor White
|
Write-Host "📊 Summary: $repoCount Git repositories detected, $updatedCount updated with new domain." -ForegroundColor White
|
||||||
Reference in New Issue
Block a user