fix(zstart): git-pull pre-step can't hang on a credential prompt

start.gitPull ran `git pull --ff-only` before starting the server; in an
environment with no cached git credentials (e.g. WSL against an HTTPS
GitHub remote) git prompted "Username for 'https://github.com':" and the
whole start blocked on stdin. Run the pull with GIT_TERMINAL_PROMPT=0 so
it fails fast, log a clear "auto-pull skipped" note, and start with the
current checkout. Bash + PowerShell.
This commit is contained in:
KellyMichels 2026-07-23 18:51:05 -05:00
parent e64829f97c
commit 512fca6213
2 changed files with 11 additions and 5 deletions

View File

@ -66,10 +66,12 @@ start_prep() { # <key>
dim " env $name=$val"
done < <(jq -r --arg k "$key" '.projects[$k].start.env // {} | to_entries[] | "\(.key)\t\(.value)"' "$ZCONFIG")
if [ "$(zproj "$key" .start.gitPull)" = "true" ] && [ -d "$root/.git" ]; then
local last
last="$( (cd "$root" && git pull --ff-only 2>&1) | tail -1 )"
dim " git pull: $last"
(cd "$root" && git rev-parse HEAD >/dev/null 2>&1) || warn " Auto-pull failed - run 'git pull' manually if needed."
# GIT_TERMINAL_PROMPT=0 so a repo that needs credentials fails fast instead
# of blocking the server start on an interactive "Username for ..." prompt.
local out rc
out="$( (cd "$root" && GIT_TERMINAL_PROMPT=0 git pull --ff-only 2>&1) )"; rc=$?
dim " git pull: $(printf '%s\n' "$out" | tail -1)"
[ "$rc" -eq 0 ] || warn " Auto-pull skipped (exit $rc) - starting with the current checkout. (git needs credentials here, or set start.gitPull=false)"
fi
}

View File

@ -199,14 +199,18 @@ function Invoke-ProjectStartPrep {
}
if ($Proj.start.gitPull -and (Test-Path (Join-Path $Proj.localRoot ".git"))) {
Push-Location -LiteralPath $Proj.localRoot
# GIT_TERMINAL_PROMPT=0 so a repo that needs credentials fails fast
# instead of blocking the server start on a "Username for ..." prompt.
$prev = $env:GIT_TERMINAL_PROMPT; $env:GIT_TERMINAL_PROMPT = "0"
try {
$pullOut = git pull --ff-only 2>&1
$last = ($pullOut | Select-Object -Last 1)
Write-Host " git pull: $last" -ForegroundColor DarkGray
if ($LASTEXITCODE -ne 0) {
Write-Host " Auto-pull failed - run 'git pull' manually if needed." -ForegroundColor Yellow
Write-Host " Auto-pull skipped - starting with the current checkout. (git needs credentials here, or set start.gitPull=false)" -ForegroundColor Yellow
}
} finally {
$env:GIT_TERMINAL_PROMPT = $prev
Pop-Location
}
}