diff --git a/reauth-gitea.ps1 b/reauth-gitea.ps1 new file mode 100644 index 0000000..7c23176 --- /dev/null +++ b/reauth-gitea.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +param( + [string]$Remote = "origin", + [string]$Branch = "main" +) + +$ErrorActionPreference = "Stop" +$HostName = "git.peli-server.de" +$Repository = $PSScriptRoot + +function Invoke-Git { + param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments) + + & git -C $Repository @Arguments + if ($LASTEXITCODE -ne 0) { + throw "Git-Befehl fehlgeschlagen: git $($Arguments -join ' ')" + } +} + +if (-not (Get-Command git -ErrorAction SilentlyContinue)) { + throw "Git wurde nicht gefunden. Installiere Git for Windows oder fuege es zum PATH hinzu." +} + +$remoteUrl = (& git -C $Repository remote get-url $Remote 2>$null) +if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($remoteUrl)) { + throw "Remote '$Remote' wurde im Repository nicht gefunden." +} + +if ($remoteUrl -notmatch [regex]::Escape($HostName)) { + throw "Sicherheitsabbruch: Remote '$Remote' zeigt nicht auf $HostName ($remoteUrl)." +} + +Write-Host "Gitea-Anmeldung fuer $HostName wird erneuert." -ForegroundColor Cyan +Write-Host "Der alte Windows-Credential-Manager-Eintrag wird jetzt entfernt." + +$credentialQuery = "protocol=https`nhost=$HostName`n`n" +$credentialQuery | & git credential reject +if ($LASTEXITCODE -ne 0) { + throw "Der alte Git-Credential-Eintrag konnte nicht entfernt werden." +} + +Write-Host "" +Write-Host "Beim folgenden Push sollte Git Credential Manager nach der Anmeldung fragen." -ForegroundColor Yellow +Write-Host "Benutzername: dein Gitea-Benutzername" +Write-Host "Passwort: dein Gitea-Passwort oder besser ein Personal Access Token" +Write-Host "Das Passwort/Token niemals hier im Chat einfuegen." +Write-Host "" + +$env:GCM_INTERACTIVE = "always" +Invoke-Git push --set-upstream $Remote $Branch + +Write-Host "" +Write-Host "Anmeldung gespeichert und Push erfolgreich." -ForegroundColor Green +Write-Host "Kuenftige Pushes aus Codex sollten wieder ohne erneute Anmeldung funktionieren."