#Requires -Version 5.1 <# .SYNOPSIS Mirror current kalinamall/main tree to remote "home" with papatramp URLs (force). .DESCRIPTION Canonical working tree stays on kalinamall. This builds a temp orphan commit with git host URLs rewritten to git.papatramp.ru and force-pushes to home. Private content (LAN, names, secrets) is kept — unlike Publish-GithubOrphan. #> param( [string]$SourceRepo = (Get-Location).Path, [string]$Branch = 'main', [string]$RemoteName = 'home' ) $ErrorActionPreference = 'Stop' $SourceRepo = (Resolve-Path $SourceRepo).Path Set-Location $SourceRepo $rewrite = Join-Path $PSScriptRoot 'Rewrite-GitHostUrls.ps1' if (-not (Test-Path $rewrite)) { throw "missing: $rewrite" } $ensure = Join-Path $PSScriptRoot 'Ensure-GiteaHomeRepo.ps1' $repoName = Split-Path -Leaf (git rev-parse --show-toplevel) if (Test-Path $ensure) { try { & powershell -NoProfile -ExecutionPolicy Bypass -File $ensure -RepoName $repoName } catch { Write-Warning "Ensure-GiteaHomeRepo: $($_.Exception.Message)" } } $remoteUrl = (git remote get-url $RemoteName).Trim() if (-not $remoteUrl) { throw "remote not found: $RemoteName" } $work = Join-Path $env:TEMP "home-mirror-$repoName-$PID" if (Test-Path $work) { Remove-Item $work -Recurse -Force } New-Item -ItemType Directory -Path $work | Out-Null $zip = Join-Path $env:TEMP "home-archive-$PID.zip" if (Test-Path $zip) { Remove-Item $zip -Force } git archive --format=zip -o $zip $Branch Expand-Archive -Path $zip -DestinationPath $work -Force Remove-Item $zip -Force & powershell -NoProfile -ExecutionPolicy Bypass -File $rewrite -Target home -Root $work Set-Location $work if (Test-Path .git) { Remove-Item .git -Recurse -Force } git init -b main | Out-Null git add -A $sha = (git -C $SourceRepo rev-parse --short HEAD).Trim() $msg = "chore(home): mirror from kalinamall ($sha) with papatramp URLs" git -c user.name='PTah' -c user.email='papatramp@gmail.com' commit -m $msg | Out-Null git remote add target $remoteUrl git push target main --force Write-Host "OK -> $remoteUrl (home mirror, force)" Set-Location $SourceRepo Remove-Item $work -Recurse -Force