Set-GitRemotes: имя repo из remote URL, не из имени папки.
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,23 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
repo_name="${REPO:-$(basename "$(git rev-parse --show-toplevel)")}"
|
||||
repo_name_from_url() {
|
||||
local url="$1"
|
||||
if [[ "$url" =~ /([^/]+)(\.git)?/?$ ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
fi
|
||||
}
|
||||
|
||||
repo_name="${REPO:-}"
|
||||
if [[ -z "$repo_name" ]]; then
|
||||
for remote in kalinamall home github origin; do
|
||||
if url="$(git remote get-url "$remote" 2>/dev/null)"; then
|
||||
repo_name="$(repo_name_from_url "$url")"
|
||||
[[ -n "$repo_name" ]] && break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
repo_name="${repo_name:-$(basename "$(git rev-parse --show-toplevel)")}"
|
||||
home_url="ssh://git@git.papatramp.ru:2222/${OWNER}/${repo_name}.git"
|
||||
kalinamall_url="ssh://git@git.kalinamall.ru:2222/${OWNER}/${repo_name}.git"
|
||||
github_url="git@github.com:${GITHUB_ORG}/${repo_name}.git"
|
||||
|
||||
Reference in New Issue
Block a user