diff --git a/scripts/githooks/pre-commit b/scripts/githooks/pre-commit index d04ba81479..2a0d9a4c46 100755 --- a/scripts/githooks/pre-commit +++ b/scripts/githooks/pre-commit @@ -14,7 +14,15 @@ set -euo pipefail cd "$(git rev-parse --show-toplevel)" -unset GIT_DIR + +# Unset all repo-local Git env vars, not just GIT_DIR. In linked +# worktrees the hook inherits variables like GIT_COMMON_DIR and +# GIT_INDEX_FILE that confuse child processes (notably Go's VCS +# stamping, which shells out to git and gets exit status 128). +# Process substitution (not a pipe) so unset runs in the current shell. +while IFS= read -r var; do + unset "$var" +done < <(git rev-parse --local-env-vars) # In linked worktrees, set worktree-scoped hooksPath to override shared config. if [[ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]]; then diff --git a/scripts/githooks/pre-push b/scripts/githooks/pre-push index 6042f4898c..50f20f62e8 100755 --- a/scripts/githooks/pre-push +++ b/scripts/githooks/pre-push @@ -30,7 +30,15 @@ ALLOWLIST=( ) cd "$(git rev-parse --show-toplevel)" -unset GIT_DIR + +# Unset all repo-local Git env vars, not just GIT_DIR. In linked +# worktrees the hook inherits variables like GIT_COMMON_DIR and +# GIT_INDEX_FILE that confuse child processes (notably Go's VCS +# stamping, which shells out to git and gets exit status 128). +# Process substitution (not a pipe) so unset runs in the current shell. +while IFS= read -r var; do + unset "$var" +done < <(git rev-parse --local-env-vars) # In linked worktrees, set worktree-scoped hooksPath to override shared config. if [[ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]]; then