diff --git a/private_dot_local/bin/executable_project_git_fetch b/private_dot_local/bin/executable_project_git_fetch index 804ad3a..ac231d9 100644 --- a/private_dot_local/bin/executable_project_git_fetch +++ b/private_dot_local/bin/executable_project_git_fetch @@ -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 \ No newline at end of file +fi