Add git fetch timeout

This commit is contained in:
Yax 2026-10-22 11:49:50 +02:00
parent da73c0e871
commit 1f78db41eb

View file

@ -1,9 +1,20 @@
#!/usr/bin/env zsh
# Max seconds to wait for the remote before giving up
FETCH_TIMEOUT=${PROJECT_GIT_FETCH_TIMEOUT:-3}
# Is this directory inside a git repo?
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# Are we at the repo root? (prefix empty = root)
if [ -z "$(git rev-parse --show-prefix)" ]; then
echo "Fetching latest changes from remote..."
git fetch
# Never prompt for credentials, fail fast on unreachable SSH hosts
GIT_TERMINAL_PROMPT=0 \
GIT_SSH_COMMAND="ssh -o ConnectTimeout=$FETCH_TIMEOUT -o BatchMode=yes" \
timeout -k 1 "$FETCH_TIMEOUT" git fetch --quiet 2>/dev/null
case $? in
0) ;;
124|137) echo "⚠ git fetch abandoned: remote unreachable after ${FETCH_TIMEOUT}s" ;;
*) echo "⚠ git fetch failed (remote unreachable or auth error)" ;;
esac
fi
fi