#Requires -Version 5.1 # Publish kalinamall/main tree to github.com/PTah as a single orphan commit (no history). # Hard sanitize: internal URLs/hosts, site names, Cursor trailers/mentions. param( [Parameter(Mandatory = $false)] [string]$SourceRepo = (Get-Location).Path, [string]$RemoteName = 'github', [string]$Version = '', [string[]]$ExcludePaths = @(), [hashtable]$OverlayFromGithub = @{} ) $ErrorActionPreference = 'Stop' $SourceRepo = (Resolve-Path $SourceRepo).Path Set-Location $SourceRepo $remoteUrl = (git remote get-url $RemoteName).Trim() if (-not $remoteUrl) { throw "remote not found: $RemoteName" } $work = Join-Path $env:TEMP "gh-orphan-$([IO.Path]::GetFileName($SourceRepo))-$PID" if (Test-Path $work) { Remove-Item $work -Recurse -Force } New-Item -ItemType Directory -Path $work | Out-Null $zip = Join-Path $env:TEMP "gh-archive-$PID.zip" if (Test-Path $zip) { Remove-Item $zip -Force } git archive --format=zip -o $zip main Expand-Archive -Path $zip -DestinationPath $work -Force Remove-Item $zip -Force foreach ($drop in @('.cursor', '.cursorignore', 'AGENTS.md', 'CURSOR.md')) { $t = Join-Path $work $drop if (Test-Path $t) { Remove-Item $t -Recurse -Force Write-Host "exclude: $drop" } } foreach ($rel in $ExcludePaths) { $target = Join-Path $work $rel if (Test-Path $target) { Remove-Item $target -Recurse -Force Write-Host "exclude: $rel" } } foreach ($entry in $OverlayFromGithub.GetEnumerator()) { $rel = $entry.Key $content = git show "${RemoteName}/main:$rel" 2>$null if ($LASTEXITCODE -ne 0) { throw "overlay missing on ${RemoteName}/main: $rel" } $out = Join-Path $work $rel $dir = Split-Path $out -Parent if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null } [IO.File]::WriteAllText($out, ($content -join "`n") + "`n", [Text.UTF8Encoding]::new($false)) Write-Host "overlay: $rel" } $textExt = @('.md', '.py', '.ts', '.vue', '.json', '.sh', '.ps1', '.yml', '.yaml', '.example', '.service', '.txt', '.html', '.css', '.kt', '.kts', '.xml', '.properties', '.gradle', '.pro') $replacements = @( @{ From = 'https://git\.kalinamall\.ru/PapaTramp/([^)/\s"''`]+)/src/branch/main/'; To = 'https://git.papatramp.ru/PapaTramp/$1/src/branch/main/' } @{ From = 'https://git\.kalinamall\.ru/PapaTramp/([^)/\s"''`]+)/blob/main/'; To = 'https://git.papatramp.ru/PapaTramp/$1/src/branch/main/' } @{ From = 'https://git\.kalinamall\.ru/PapaTramp/'; To = 'https://git.papatramp.ru/PapaTramp/' } @{ From = 'git\.kalinamall\.ru/PapaTramp/'; To = 'git.papatramp.ru/PapaTramp/' } @{ From = 'https://git\.papatramp\.ru/(PapaTramp|PTah)/'; To = 'https://git.papatramp.ru/PapaTramp/' } @{ From = 'git\.papatramp\.ru/(PapaTramp|PTah)/'; To = 'git.papatramp.ru/PapaTramp/' } @{ From = 'ssh://git@git\.kalinamall\.ru:2222/PapaTramp/'; To = 'https://git.papatramp.ru/PapaTramp/' } @{ From = 'ssh://git@git\.papatramp\.ru:2222/PapaTramp/'; To = 'https://git.papatramp.ru/PapaTramp/' } @{ From = 'sac-api\.kalinamall\.ru'; To = 'sac-api.example.com' } @{ From = 'sac\.kalinamall\.ru'; To = 'sac.example.com' } @{ From = 'ext\.kalinamall\.ru'; To = 'ext.example.com' } @{ From = '\*\.kalinamall\.ru'; To = '*.example.com' } @{ From = 'kalinamall\.ru'; To = 'example.com' } @{ From = 'papatramp\.lan'; To = 'example.lan' } @{ From = '192\.168\.\d+\.\d+'; To = '10.0.0.1' } @{ From = 'Co-authored-by:\s*Cursor\s*\s*'; To = '' } @{ From = 'Made-with:\s*Cursor\s*'; To = '' } @{ From = 'Cursor Agent'; To = '' } @{ From = 'Cursor IDE'; To = '' } @{ From = 'cursoragent@cursor\.com'; To = '' } @{ From = '(?i)\bpowered by cursor\b'; To = '' } @{ From = 'B26\\'; To = 'CONTOSO\' } @{ From = 'B26/'; To = 'CONTOSO/' } @{ From = 'K6A-DC\d'; To = 'WIN-DC01' } @{ From = 'UNMS Kalina'; To = 'Example Site' } @{ From = 'k\.khodasevich'; To = 'user1' } @{ From = '\bkalinamall\b'; To = 'example' } @{ From = '\bpapatramp\b'; To = 'jdoe' } ) Get-ChildItem -Path $work -Recurse -File | ForEach-Object { $ext = $_.Extension.ToLowerInvariant() if ($textExt -notcontains $ext -and $_.Name -notmatch '\.(example|service)$') { return } $content = [IO.File]::ReadAllText($_.FullName) $updated = $content foreach ($r in $replacements) { $updated = [regex]::Replace($updated, $r.From, $r.To) } if ($updated -ne $content) { [IO.File]::WriteAllText($_.FullName, $updated, [Text.UTF8Encoding]::new($false)) } } $forbidden = @( 'git\.kalinamall\.ru', 'git\.papatramp\.ru', 'papatramp\.lan', '192\.168\.\d+\.\d+', 'cursoragent@cursor\.com', 'Co-authored-by:\s*Cursor', 'Made-with:\s*Cursor', '(?i)Cursor Agent', '(?i)Cursor IDE', '(?i)powered by cursor', '\bkalinamall\b', '\bpapatramp\b', 'K6A-DC', 'B26\\' ) $hits = 0 Get-ChildItem -Path $work -Recurse -File | ForEach-Object { $ext = $_.Extension.ToLowerInvariant() if ($textExt -notcontains $ext -and $_.Name -notmatch '\.(example|service)$') { return } $content = [IO.File]::ReadAllText($_.FullName) foreach ($pat in $forbidden) { if ([regex]::IsMatch($content, $pat)) { $rel = $_.FullName.Substring($work.Length + 1) Write-Warning "FORBIDDEN '$pat' in $rel" $script:hits++ } } } if ($hits -gt 0) { throw "sanitization failed: $hits forbidden pattern(s)" } Set-Location $work if (Test-Path .git) { Remove-Item .git -Recurse -Force } git init -b main | Out-Null git add -A $msg = if ($Version) { "chore(github): sync public mirror ($Version)" } else { 'chore(github): sync public mirror' } git -c user.name='PTah' -c user.email='papatramp@gmail.com' commit -m $msg git remote add target $remoteUrl git push target main --force Write-Host "OK -> $remoteUrl (orphan, force)" Set-Location $SourceRepo Remove-Item $work -Recurse -Force