From 584ddde1d13f124ff85fba9883e385a430b0e20d Mon Sep 17 00:00:00 2001 From: PTah Date: Fri, 19 Jun 2026 23:34:45 +1000 Subject: [PATCH] =?UTF-8?q?Set-GitRemotes:=20=D0=B8=D0=BC=D1=8F=20repo=20?= =?UTF-8?q?=D0=B8=D0=B7=20remote=20URL,=20=D0=BD=D0=B5=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BF=D0=B0=D0=BF=D0=BA=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Set-GitRemotes.ps1 | 17 +++++++++++++++++ scripts/Set-GitRemotes.sh | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/Set-GitRemotes.ps1 b/scripts/Set-GitRemotes.ps1 index f0684f2..c166009 100644 --- a/scripts/Set-GitRemotes.ps1 +++ b/scripts/Set-GitRemotes.ps1 @@ -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)) } diff --git a/scripts/Set-GitRemotes.sh b/scripts/Set-GitRemotes.sh index 1a03a04..7492b4b 100644 --- a/scripts/Set-GitRemotes.sh +++ b/scripts/Set-GitRemotes.sh @@ -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"