fix(§3.3): Disable GCM + set GIT_TERMINAL_PROMPT=0 in WinRM guest clone

Git Credential Manager (GCM) installed by Git for Windows tries to open
an interactive credential prompt or wincredman store — both fail in a
WinRM session (no TTY, no interactive desktop).

Fix:
- Set GIT_TERMINAL_PROMPT=0 to suppress all interactive git prompts
- Prepend '-c credential.helper=' (empty string) to reset the helper chain
  before injecting our store-based helper (clearing GCM from the chain)
- Custom credential helper (store --file <tmp>) then appended only when PAT present

Without PAT (public repo): GCM still cleared, no prompt attempted, clean fail
  if auth is actually required.
With PAT: store-based helper used exclusively, GCM never invoked.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Simone
2026-05-10 22:10:01 +02:00
parent eb6fdfb2ca
commit 73fca1c74a
+10 -1
View File
@@ -245,6 +245,13 @@ try {
if ($submodules) { $gitArgs += '--recurse-submodules' } if ($submodules) { $gitArgs += '--recurse-submodules' }
$gitArgs += @($cloneUrl, (Split-Path $workDir -Leaf)) $gitArgs += @($cloneUrl, (Split-Path $workDir -Leaf))
# Disable interactive credential prompts — WinRM has no TTY
$env:GIT_TERMINAL_PROMPT = '0'
# Clear any system credential helper (e.g. GCM) that may try to open UI/TTY.
# '-c credential.helper=' (empty) resets the helper chain before we inject ours.
$credHelperArgs = @('-c', 'credential.helper=')
# Credentials via temp .git-credentials file (§1.5: token never in URL, argv, or logs) # Credentials via temp .git-credentials file (§1.5: token never in URL, argv, or logs)
$tmpCreds = $null $tmpCreds = $null
if ($patUser -and $patPass) { if ($patUser -and $patPass) {
@@ -252,9 +259,11 @@ try {
$credLine = "$($uri.Scheme)://${patUser}:${patPass}@$($uri.Host)" $credLine = "$($uri.Scheme)://${patUser}:${patPass}@$($uri.Host)"
$tmpCreds = "C:\CI\tmp_gc_$([guid]::NewGuid().ToString('N'))" $tmpCreds = "C:\CI\tmp_gc_$([guid]::NewGuid().ToString('N'))"
[System.IO.File]::WriteAllText($tmpCreds, $credLine) [System.IO.File]::WriteAllText($tmpCreds, $credLine)
$gitArgs = @('-c', "credential.helper=store --file $tmpCreds") + $gitArgs $credHelperArgs += @('-c', "credential.helper=store --file $tmpCreds")
} }
$gitArgs = $credHelperArgs + $gitArgs
try { try {
Write-Host "[Guest] Cloning $cloneUrl (branch: $branch)..." Write-Host "[Guest] Cloning $cloneUrl (branch: $branch)..."
& git @gitArgs 2>&1 | ForEach-Object { Write-Host "[Guest Clone] $_" } & git @gitArgs 2>&1 | ForEach-Object { Write-Host "[Guest Clone] $_" }