Add Gitea reauthentication helper

This commit is contained in:
2026-07-16 20:34:02 +02:00
parent 215df3f75d
commit a91b354295
+54
View File
@@ -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."