mirror of
https://gitea.zaclys.com/yannic/dotfiles.git
synced 2026-11-10 20:35:13 +01:00
Add git fetch timeout
This commit is contained in:
@@ -1,9 +1,20 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/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?
|
# Is this directory inside a git repo?
|
||||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
# Are we at the repo root? (prefix empty = root)
|
# Are we at the repo root? (prefix empty = root)
|
||||||
if [ -z "$(git rev-parse --show-prefix)" ]; then
|
if [ -z "$(git rev-parse --show-prefix)" ]; then
|
||||||
echo "Fetching latest changes from remote..."
|
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
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user