Set-GitRemotes: имя repo из remote URL, не из имени папки.

This commit is contained in:
2026-06-19 23:34:45 +10:00
parent 25f4d5972e
commit 584ddde1d1
2 changed files with 34 additions and 1 deletions
+17
View File
@@ -29,9 +29,26 @@ function Test-GitRepo {
}
}
function Get-RepoNameFromRemoteUrl {
param([string]$Url)
if ($Url -match '/([^/]+?)(?:\.git)?/?$') {
return $Matches[1]
}
return $null
}
function Get-RepoName {
param([string]$Name)
if ($Name) { return $Name }
foreach ($remote in @('kalinamall', 'home', 'github', 'origin')) {
$url = git remote get-url $remote 2>$null
if ($url) {
$fromUrl = Get-RepoNameFromRemoteUrl -Url $url.Trim()
if ($fromUrl) { return $fromUrl }
}
}
return (Split-Path -Leaf (git rev-parse --show-toplevel))
}