Remotes: kalinamall, home, github по SSH (.ru); origin убран.

Set-GitRemotes переименует origin по хосту; SSH config для .ru через LAN IP.
This commit is contained in:
2026-06-18 11:34:03 +10:00
parent 7f8e7c0cb2
commit 4caedb3074
8 changed files with 77 additions and 39 deletions
+9 -1
View File
@@ -50,7 +50,15 @@ init-cursor --update
3. Копирует `.cursorignore`, `.cursor/rules/*.mdc`, дополняет `.gitignore` 3. Копирует `.cursorignore`, `.cursor/rules/*.mdc`, дополняет `.gitignore`
4. `Set-GitRemotes*` + `Ensure-GiteaHomeRepo.ps1` для текущего репозитория 4. `Set-GitRemotes*` + `Ensure-GiteaHomeRepo.ps1` для текущего репозитория
`bootstrap.ps1` / `bootstrap.sh` оставлены для ручного запуска без проекта. ## Git remotes
| Remote | Хост | URL |
|--------|------|-----|
| `kalinamall` | git.kalinamall.ru | `ssh://git@git.kalinamall.ru:2222/PapaTramp/<Repo>.git` |
| `home` | git.papatramp.ru | `ssh://git@git.papatramp.ru:2222/PapaTramp/<Repo>.git` |
| `github` | github.com/PTah | `git@github.com:PTah/<Repo>.git` |
`origin` не используется. `Set-GitRemotes` переименует старый `origin` по хосту. Push/pull Rules: `git push kalinamall`.
## Конфиги (local/) ## Конфиги (local/)
+1 -1
View File
@@ -18,7 +18,7 @@ $ErrorActionPreference = 'Stop'
$rulesDest = Join-Path $HOME 'CursorRules' $rulesDest = Join-Path $HOME 'CursorRules'
$httpsUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git' $httpsUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git'
$sshUrl = 'ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git' $sshUrl = 'ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git'
if (-not (Test-Path (Join-Path $rulesDest '.git'))) { if (-not (Test-Path (Join-Path $rulesDest '.git'))) {
Write-Host '[*] Cloning Rules from Gitea (HTTPS, login once if asked)...' -ForegroundColor Cyan Write-Host '[*] Cloning Rules from Gitea (HTTPS, login once if asked)...' -ForegroundColor Cyan
+2 -2
View File
@@ -6,7 +6,7 @@ KeyComment=papatramp@kalinamall
GiteaConfig=kalinamall-gitea.conf GiteaConfig=kalinamall-gitea.conf
[host:git.kalinamall.ru] [host:git.kalinamall.ru]
HostName=git.kalinamall.ru HostName=192.168.160.129
Port=2222 Port=2222
User=git User=git
Profile=kalinamall-git Profile=kalinamall-git
@@ -23,7 +23,7 @@ KeyComment=papatramp@papatramp.ru
GiteaConfig=papatramp-gitea.conf GiteaConfig=papatramp-gitea.conf
[host:git.papatramp.ru] [host:git.papatramp.ru]
HostName=git.papatramp.ru HostName=192.168.128.48
Port=2222 Port=2222
User=git User=git
Profile=papatramp-git Profile=papatramp-git
+4 -4
View File
@@ -7,7 +7,7 @@
param( param(
[Parameter(Mandatory = $true)][string]$Root, [Parameter(Mandatory = $true)][string]$Root,
[string]$RulesDest = '', [string]$RulesDest = '',
[string]$CloneUrl = 'ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git', [string]$CloneUrl = 'ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git',
[string]$HttpsCloneUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git', [string]$HttpsCloneUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git',
[switch]$SkipClone, [switch]$SkipClone,
[switch]$SkipProfile, [switch]$SkipProfile,
@@ -66,7 +66,7 @@ function Test-MachineGitReady {
if (-not (Test-Path -LiteralPath $keyPath)) { return $false } if (-not (Test-Path -LiteralPath $keyPath)) { return $false }
} }
if ($sshText -notmatch '(?m)^Host\s+git\.kalinamall\.lan\s*$') { return $false } if ($sshText -notmatch '(?m)^Host\s+git\.kalinamall\.ru\s*$') { return $false }
return $true return $true
} }
@@ -182,8 +182,8 @@ $registerArgs = @{ ConfigDir = $configDir; WhatIf = $WhatIf.IsPresent }
& (Join-Path $Root 'scripts\Register-GiteaSshKeys.ps1') @registerArgs & (Join-Path $Root 'scripts\Register-GiteaSshKeys.ps1') @registerArgs
if (-not $WhatIf) { if (-not $WhatIf) {
Write-Step 'Testing git@git.kalinamall.lan' Write-Step 'Testing git@git.kalinamall.ru'
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.lan 2>&1 | ForEach-Object { Write-Host $_ } ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.ru 2>&1 | ForEach-Object { Write-Host $_ }
} }
} }
elseif ($gitReady) { elseif ($gitReady) {
+26 -8
View File
@@ -1,7 +1,7 @@
#Requires -Version 5.1 #Requires -Version 5.1
<# <#
.SYNOPSIS .SYNOPSIS
Стандартные git remote: home, kalinamall, github. Стандартные git remote: home (papatramp), kalinamall, github (PTah).
.EXAMPLE .EXAMPLE
cd C:\Users\papat\Projects\MyRepo cd C:\Users\papat\Projects\MyRepo
@@ -35,13 +35,23 @@ function Get-RepoName {
return (Split-Path -Leaf (git rev-parse --show-toplevel)) return (Split-Path -Leaf (git rev-parse --show-toplevel))
} }
function Get-OriginRemoteTarget {
$url = (git remote get-url origin 2>$null)
if (-not $url) { return $null }
$lower = $url.ToLower()
if ($lower -match 'kalinamall') { return 'kalinamall' }
if ($lower -match 'papatramp') { return 'home' }
if ($lower -match 'github\.com') { return 'github' }
return $null
}
function Set-Remote { function Set-Remote {
param( param(
[string]$Name, [string]$Name,
[string]$Url [string]$Url
) )
$existing = git remote 2>$null $existing = @(git remote 2>$null)
$has = $existing -contains $Name $has = $existing -contains $Name
if ($WhatIf) { if ($WhatIf) {
@@ -60,9 +70,19 @@ function Set-Remote {
return return
} }
if ($existing -contains 'origin') {
$originTarget = Get-OriginRemoteTarget
if ($originTarget -eq $Name) {
git remote rename origin $Name
git remote set-url $Name $Url
Write-Ok "remote origin renamed to $Name -> $Url"
return
}
}
$legacy = @{ $legacy = @{
home = @('gitea', 'papatramp', 'origin-home') home = @('gitea', 'papatramp', 'origin-home')
github = @('origin') github = @()
kalinamall = @('gitea-kalinamall', 'kalina') kalinamall = @('gitea-kalinamall', 'kalina')
} }
foreach ($old in $legacy[$Name]) { foreach ($old in $legacy[$Name]) {
@@ -81,16 +101,14 @@ function Set-Remote {
Test-GitRepo Test-GitRepo
$repoName = Get-RepoName -Name $Repo $repoName = Get-RepoName -Name $Repo
$homeUrl = "ssh://git@git.papatramp.lan:2222/${Owner}/${repoName}.git" $homeUrl = "ssh://git@git.papatramp.ru:2222/${Owner}/${repoName}.git"
$kalinamallUrl = "ssh://git@git.kalinamall.lan:2222/${Owner}/${repoName}.git" $kalinamallUrl = "ssh://git@git.kalinamall.ru:2222/${Owner}/${repoName}.git"
$githubUrl = "git@github.com:${GithubOrg}/${repoName}.git" $githubUrl = "git@github.com:${GithubOrg}/${repoName}.git"
Write-Step "Repo: $repoName" Write-Step "Repo: $repoName"
Set-Remote -Name 'home' -Url $homeUrl Set-Remote -Name 'home' -Url $homeUrl
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
Set-Remote -Name 'github' -Url $githubUrl Set-Remote -Name 'github' -Url $githubUrl
if (-not $SkipKalinamall) {
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
}
Write-Host '' Write-Host ''
Write-Host 'Remotes:' -ForegroundColor Magenta Write-Host 'Remotes:' -ForegroundColor Magenta
+25 -9
View File
@@ -1,11 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Стандартные git remote: home, kalinamall, github. # Стандартные git remote: home (papatramp), kalinamall, github (PTah).
set -euo pipefail set -euo pipefail
OWNER="${OWNER:-PapaTramp}" OWNER="${OWNER:-PapaTramp}"
GITHUB_ORG="${GITHUB_ORG:-PTah}" GITHUB_ORG="${GITHUB_ORG:-PTah}"
REPO="${REPO:-}" REPO="${REPO:-}"
SKIP_KALINAMALL="${SKIP_KALINAMALL:-0}"
WHAT_IF="${WHAT_IF:-0}" WHAT_IF="${WHAT_IF:-0}"
log_step() { printf '[*] %s\n' "$1"; } log_step() { printf '[*] %s\n' "$1"; }
@@ -17,14 +16,23 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
fi fi
repo_name="${REPO:-$(basename "$(git rev-parse --show-toplevel)")}" repo_name="${REPO:-$(basename "$(git rev-parse --show-toplevel)")}"
home_url="ssh://git@git.papatramp.lan:2222/${OWNER}/${repo_name}.git" home_url="ssh://git@git.papatramp.ru:2222/${OWNER}/${repo_name}.git"
kalinamall_url="ssh://git@git.kalinamall.lan: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" github_url="git@github.com:${GITHUB_ORG}/${repo_name}.git"
origin_remote_target() {
local url
url="$(git remote get-url origin 2>/dev/null | tr '[:upper:]' '[:lower:]' || true)"
[[ -z "$url" ]] && return 0
if [[ "$url" == *kalinamall* ]]; then echo kalinamall; return 0; fi
if [[ "$url" == *papatramp* ]]; then echo home; return 0; fi
if [[ "$url" == *github.com* ]]; then echo github; return 0; fi
}
set_remote() { set_remote() {
local name="$1" local name="$1"
local url="$2" local url="$2"
local existing current old local existing current old origin_target
if [[ "$WHAT_IF" == '1' ]]; then if [[ "$WHAT_IF" == '1' ]]; then
log_step "WhatIf: remote $name -> $url" log_step "WhatIf: remote $name -> $url"
@@ -42,9 +50,19 @@ set_remote() {
return 0 return 0
fi fi
if git remote | grep -Fxq origin; then
origin_target="$(origin_remote_target || true)"
if [[ "$origin_target" == "$name" ]]; then
git remote rename origin "$name"
git remote set-url "$name" "$url"
log_ok "remote origin renamed to $name -> $url"
return 0
fi
fi
case "$name" in case "$name" in
home) legacy=(gitea papatramp origin-home) ;; home) legacy=(gitea papatramp origin-home) ;;
github) legacy=(origin) ;; github) legacy=() ;;
kalinamall) legacy=(gitea-kalinamall kalina) ;; kalinamall) legacy=(gitea-kalinamall kalina) ;;
*) legacy=() ;; *) legacy=() ;;
esac esac
@@ -64,10 +82,8 @@ set_remote() {
log_step "Repo: $repo_name" log_step "Repo: $repo_name"
set_remote home "$home_url" set_remote home "$home_url"
set_remote kalinamall "$kalinamall_url"
set_remote github "$github_url" set_remote github "$github_url"
if [[ "$SKIP_KALINAMALL" != '1' ]]; then
set_remote kalinamall "$kalinamall_url"
fi
printf '\n' printf '\n'
git remote -v git remote -v
+6 -10
View File
@@ -85,20 +85,16 @@ function Get-SshConfigBlock {
) -join "`n" ) -join "`n"
} }
function Update-SshConfig { function Update-SshConfigText {
param( param(
[string]$ConfigPath, [string]$ExistingText,
[string]$HostAlias, [string]$HostAlias,
[string]$Block [string]$Block
) )
$begin = "# BEGIN Setup-SshAccess:$HostAlias" $begin = "# BEGIN Setup-SshAccess:$HostAlias"
$end = "# END Setup-SshAccess:$HostAlias" $end = "# END Setup-SshAccess:$HostAlias"
$existing = if (Test-Path -LiteralPath $ConfigPath) { $existing = $ExistingText
Get-Content -LiteralPath $ConfigPath -Raw
} else {
''
}
$pattern = "(?ms)^$([regex]::Escape($begin)).*?$([regex]::Escape($end))\r?\n?" $pattern = "(?ms)^$([regex]::Escape($begin)).*?$([regex]::Escape($end))\r?\n?"
if ($existing -match $pattern) { if ($existing -match $pattern) {
@@ -174,7 +170,7 @@ foreach ($hostAlias in ($parsed.Hosts.Keys | Sort-Object)) {
continue continue
} }
$configText = Update-SshConfig -ConfigPath $sshConfigPath -HostAlias $hostAlias -Block $block $configText = Update-SshConfigText -ExistingText $configText -HostAlias $hostAlias -Block $block
Write-Ok "ssh config: $hostAlias" Write-Ok "ssh config: $hostAlias"
} }
@@ -183,12 +179,12 @@ if (-not $WhatIf) {
Add-Content -LiteralPath $sshConfigPath -Value '' -Encoding UTF8 Add-Content -LiteralPath $sshConfigPath -Value '' -Encoding UTF8
Get-Service ssh-agent -ErrorAction SilentlyContinue | Where-Object { $_.Status -ne 'Running' } | Get-Service ssh-agent -ErrorAction SilentlyContinue | Where-Object { $_.Status -ne 'Running' } |
ForEach-Object { Start-Service ssh-agent | Out-Null } ForEach-Object { Start-Service ssh-agent -ErrorAction SilentlyContinue | Out-Null }
foreach ($keyName in $profileKeys.Keys) { foreach ($keyName in $profileKeys.Keys) {
$keyPath = Join-Path $sshDir $keyName $keyPath = Join-Path $sshDir $keyName
if (Test-Path -LiteralPath $keyPath) { if (Test-Path -LiteralPath $keyPath) {
ssh-add $keyPath 2>$null | Out-Null try { ssh-add $keyPath 2>$null | Out-Null } catch { }
} }
} }
} }
+4 -4
View File
@@ -4,7 +4,7 @@ set -euo pipefail
ROOT="${ROOT:?ROOT is required}" ROOT="${ROOT:?ROOT is required}"
RULES_DEST="${RULES_DEST:-$HOME/CursorRules}" RULES_DEST="${RULES_DEST:-$HOME/CursorRules}"
CLONE_URL="${CLONE_URL:-ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git}" CLONE_URL="${CLONE_URL:-ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git}"
HTTPS_CLONE_URL="${HTTPS_CLONE_URL:-https://git.kalinamall.ru/PapaTramp/Rules.git}" HTTPS_CLONE_URL="${HTTPS_CLONE_URL:-https://git.kalinamall.ru/PapaTramp/Rules.git}"
SKIP_CLONE="${SKIP_CLONE:-0}" SKIP_CLONE="${SKIP_CLONE:-0}"
SKIP_PROFILE="${SKIP_PROFILE:-0}" SKIP_PROFILE="${SKIP_PROFILE:-0}"
@@ -22,7 +22,7 @@ test_machine_git_ready() {
local hosts_config="$CONFIG_DIR/git-ssh-hosts.conf" local hosts_config="$CONFIG_DIR/git-ssh-hosts.conf"
local ssh_config="$HOME/.ssh/config" local ssh_config="$HOME/.ssh/config"
[[ -f "$hosts_config" && -f "$ssh_config" ]] || return 1 [[ -f "$hosts_config" && -f "$ssh_config" ]] || return 1
grep -q '^Host git.kalinamall.lan$' "$ssh_config" || return 1 grep -q '^Host git.kalinamall.ru$' "$ssh_config" || return 1
local line current_profile='' key_name local line current_profile='' key_name
while IFS= read -r line || [[ -n "$line" ]]; do while IFS= read -r line || [[ -n "$line" ]]; do
@@ -109,8 +109,8 @@ if [[ "$git_ready" -eq 0 && "$SKIP_GIT_SETUP" != '1' ]]; then
export CONFIG_DIR WHAT_IF export CONFIG_DIR WHAT_IF
bash "$ROOT/scripts/setup-git-ssh.sh" bash "$ROOT/scripts/setup-git-ssh.sh"
bash "$ROOT/scripts/register-gitea-ssh-keys.sh" bash "$ROOT/scripts/register-gitea-ssh-keys.sh"
log_step 'Testing git@git.kalinamall.lan' log_step 'Testing git@git.kalinamall.ru'
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.lan || true ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.ru || true
elif [[ "$git_ready" -eq 1 ]]; then elif [[ "$git_ready" -eq 1 ]]; then
log_ok 'Git SSH already configured' log_ok 'Git SSH already configured'
fi fi