re-clone when git reports dubious ownership on the working copy
a clone first created from an elevated prompt is owned by Administrators; a later normal-user run then fails every git op with 'dubious ownership' (exit 128), which the launcher misreported as an auth error. detect that case and remove the clone for a clean re-clone.
This commit is contained in:
@@ -91,6 +91,23 @@ function Clear-InterruptedRun {
|
|||||||
Write-Host "==> Removing incomplete clone at $Target" -ForegroundColor Cyan
|
Write-Host "==> Removing incomplete clone at $Target" -ForegroundColor Cyan
|
||||||
Remove-Item -Path $Target -Recurse -Force
|
Remove-Item -Path $Target -Recurse -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# A clone created by an elevated (Administrator) run is owned by
|
||||||
|
# BUILTIN\Administrators; a later non-elevated run then trips git's
|
||||||
|
# "detected dubious ownership" guard and every git op fails with exit 128.
|
||||||
|
# That stale clone is effectively unusable for this user, so detect the
|
||||||
|
# condition and remove it here for a clean re-clone rather than surfacing a
|
||||||
|
# misleading auth error later.
|
||||||
|
if (Test-Path (Join-Path $Target '.git')) {
|
||||||
|
$previous = $ErrorActionPreference
|
||||||
|
$ErrorActionPreference = 'Continue'
|
||||||
|
try { $probe = git -C $Target rev-parse --is-inside-work-tree 2>&1 } catch { $probe = "$_" }
|
||||||
|
finally { $ErrorActionPreference = $previous }
|
||||||
|
if ($probe -match 'dubious ownership') {
|
||||||
|
Write-Host "==> Removing clone with mismatched ownership at $Target (was it created from an elevated prompt?)" -ForegroundColor Cyan
|
||||||
|
Remove-Item -Path $Target -Recurse -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Plain https URL. No token in the URL: Git Credential Manager injects the
|
# Plain https URL. No token in the URL: Git Credential Manager injects the
|
||||||
|
|||||||
Reference in New Issue
Block a user