Skip to content

Commit 9c438a2

Browse files
committed
docs(scrub_git_env): trim docstring; move bug narrative to commit
Failure scenario, root-cause deep-dive, and no_git_env allowlist enumeration belong in git history, not in source. Keep only: - what the function does and why each var is included - the pre-commit framework design constraint + issue link - the denylist-vs-allowlist note Assisted-by: Sisyphus:claude-sonnet-4-6 opencode
1 parent a063ed2 commit 9c438a2

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

hooks/_common.sh

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,32 +117,16 @@ function common::parse_cmdline {
117117
}
118118

119119
#######################################################################
120-
# Scrub some GIT_* env vars before child Git operations.
120+
# Scrub GIT_* vars that leak the parent repo location into child Git
121+
# processes (see https://git-scm.com/docs/git#_environment_variables).
121122
#
122-
# Without this, `git commit` from a linked Git worktree fails at
123-
# tree-build when a hook runs `tofu init` / `terraform init` (which
124-
# spawns `git clone` for each Git-sourced module):
125-
#
126-
# error: invalid object 100644 <oid> for '<path>'
127-
# error: Error building trees
128-
#
129-
# Root cause: the child `git clone` inherits GIT_INDEX_FILE from the
130-
# parent `git commit` env (pointing at the worktree's index), then
131-
# writes the cloned module's blob OIDs into the parent worktree's
132-
# index. The subsequent commit cannot resolve those OIDs.
133-
#
134-
# pre-commit scrubs GIT_* only for its own internal Git calls, not
135-
# for hook subprocesses - hook authors are expected to handle it
136-
# themselves: https://github.com/pre-commit/pre-commit/issues/1849
123+
# pre-commit scrubs GIT_* only for its own internal Git calls, not for
124+
# hook subprocesses - hook authors must handle it themselves:
125+
# https://github.com/pre-commit/pre-commit/issues/1849
137126
#
138127
# This is a targeted denylist, NOT a mirror of pre-commit's
139-
# allowlist-based `no_git_env` helper
140-
# (https://github.com/pre-commit/pre-commit/blob/main/pre_commit/git.py),
141-
# which drops all GIT_* except known-safe vars (GIT_ASKPASS,
142-
# GIT_CONFIG_*, GIT_SSH, GIT_SSH_COMMAND, GIT_SSL_*, etc.). We unset
143-
# only the vars that leak the parent repository's location into child
144-
# Git processes (see "Environment Variables" in `man 1 git`,
145-
# https://git-scm.com/docs/git#_environment_variables):
128+
# allowlist-based no_git_env helper. We unset only the vars that leak
129+
# the parent repository's location into child Git processes:
146130
#
147131
# GIT_DIR makes child Git operate on the parent repo
148132
# GIT_INDEX_FILE proximate cause of the failure above

0 commit comments

Comments
 (0)