Add git fetch timeout
This commit is contained in:
parent
da73c0e871
commit
1f78db41eb
1 changed files with 13 additions and 2 deletions
|
|
@ -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
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue