Remotes: kalinamall, home, github по SSH (.ru); origin убран.
Set-GitRemotes переименует origin по хосту; SSH config для .ru через LAN IP.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Стандартные git remote: home, kalinamall, github.
|
||||
Стандартные git remote: home (papatramp), kalinamall, github (PTah).
|
||||
|
||||
.EXAMPLE
|
||||
cd C:\Users\papat\Projects\MyRepo
|
||||
@@ -35,13 +35,23 @@ function Get-RepoName {
|
||||
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 {
|
||||
param(
|
||||
[string]$Name,
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
$existing = git remote 2>$null
|
||||
$existing = @(git remote 2>$null)
|
||||
$has = $existing -contains $Name
|
||||
|
||||
if ($WhatIf) {
|
||||
@@ -60,9 +70,19 @@ function Set-Remote {
|
||||
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 = @{
|
||||
home = @('gitea', 'papatramp', 'origin-home')
|
||||
github = @('origin')
|
||||
github = @()
|
||||
kalinamall = @('gitea-kalinamall', 'kalina')
|
||||
}
|
||||
foreach ($old in $legacy[$Name]) {
|
||||
@@ -81,16 +101,14 @@ function Set-Remote {
|
||||
Test-GitRepo
|
||||
$repoName = Get-RepoName -Name $Repo
|
||||
|
||||
$homeUrl = "ssh://git@git.papatramp.lan:2222/${Owner}/${repoName}.git"
|
||||
$kalinamallUrl = "ssh://git@git.kalinamall.lan:2222/${Owner}/${repoName}.git"
|
||||
$homeUrl = "ssh://git@git.papatramp.ru:2222/${Owner}/${repoName}.git"
|
||||
$kalinamallUrl = "ssh://git@git.kalinamall.ru:2222/${Owner}/${repoName}.git"
|
||||
$githubUrl = "git@github.com:${GithubOrg}/${repoName}.git"
|
||||
|
||||
Write-Step "Repo: $repoName"
|
||||
Set-Remote -Name 'home' -Url $homeUrl
|
||||
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
|
||||
Set-Remote -Name 'github' -Url $githubUrl
|
||||
if (-not $SkipKalinamall) {
|
||||
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host 'Remotes:' -ForegroundColor Magenta
|
||||
|
||||
Reference in New Issue
Block a user