diff --git a/scripts/Start-ShopDBDev.ps1 b/scripts/Start-ShopDBDev.ps1 index ec6ff9f8..bd0e8a48 100644 --- a/scripts/Start-ShopDBDev.ps1 +++ b/scripts/Start-ShopDBDev.ps1 @@ -91,6 +91,23 @@ function Clear-InterruptedRun { Write-Host "==> Removing incomplete clone at $Target" -ForegroundColor Cyan 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