Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Scrub caller git -c config from hook fixtures (PRD-9025) (#6068)

Andrew Mikofalvy5bc8e79e88da
diff --git a/lint-plugins/no-comments/README.md b/lint-plugins/no-comments/README.md
index 64a284440..401b19f51 100644
--- a/lint-plugins/no-comments/README.md
+++ b/lint-plugins/no-comments/README.md
@@ -551,8 +551,8 @@ The Git environment scrub mirrors `scripts/git-clean-env.mjs`. The hook import-c
above prevents importing that helper into this module, so a parity test keeps the local scrub
aligned with the canonical helper; the local copy additionally fixes `LC_ALL=C` for diagnostic
classification. Repository redirection and upward-discovery controls are removed before Git runs.
-The baseline scrub removes GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE, and GIT_PREFIX. The discovery controls add GIT_CEILING_DIRECTORIES and GIT_DISCOVERY_ACROSS_FILESYSTEM for this scope; they do not redefine every Git helper's contract. Git configuration, including configured ignore files,
-remains an input: this scrub is not isolation from all Git configuration.
+The baseline scrub removes GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE, and GIT_PREFIX. The discovery controls add GIT_CEILING_DIRECTORIES and GIT_DISCOVERY_ACROSS_FILESYSTEM for this scope; they do not redefine every Git helper's contract. Caller command-scope configuration is also removed: GIT_CONFIG_PARAMETERS, GIT_CONFIG_COUNT and the indexed GIT_CONFIG_KEY_<n>/GIT_CONFIG_VALUE_<n> entries. Git configuration files, including configured ignore files,
+remain an input: this scrub is not isolation from all Git configuration.
Static `exclude` rules and Git ignore rules serve different boundaries. Static exclusions also
work for non-Git adopters and can prune directories before filesystem traversal. Git filtering
diff --git a/lint-plugins/no-comments/scope.mjs b/lint-plugins/no-comments/scope.mjs
index 36ec0c503..8e4a4acc9 100644
--- a/lint-plugins/no-comments/scope.mjs
+++ b/lint-plugins/no-comments/scope.mjs
@@ -14,6 +14,7 @@ import { GRAMMAR_EXTRACTORS } from './extractors.mjs';
import { isFresh, sourceDigest } from './freshness.mjs';
const REGEX_METACHARACTERS = /[.+^${}()|[\]\\]/g;
+const INDEXED_GIT_CONFIG_ENTRY = /^GIT_CONFIG_(?:KEY|VALUE)_\d+$/;
export function globToRegExp(glob) {
if (UNSUPPORTED_GLOB_SYNTAX.test(glob)) {
@@ -52,9 +53,14 @@ export function gitEnvironment(base = process.env) {
GIT_PREFIX: _gitPrefix,
GIT_CEILING_DIRECTORIES: _gitCeilingDirectories,
GIT_DISCOVERY_ACROSS_FILESYSTEM: _gitDiscoveryAcrossFilesystem,
+ GIT_CONFIG_PARAMETERS: _gitConfigParameters,
+ GIT_CONFIG_COUNT: _gitConfigCount,
...env
} = base;
- return { ...env, LC_ALL: 'C' };
+ return {
+ ...Object.fromEntries(Object.entries(env).filter(([name]) => !INDEXED_GIT_CONFIG_ENTRY.test(name))),
+ LC_ALL: 'C',
+ };
}
function runGit(repoRoot, args, input) {
diff --git a/lint-plugins/no-comments/scope.test.mjs b/lint-plugins/no-comments/scope.test.mjs
index f81bad4d5..129741254 100644
--- a/lint-plugins/no-comments/scope.test.mjs
+++ b/lint-plugins/no-comments/scope.test.mjs
@@ -448,7 +448,11 @@ describe('gitignored output is outside discovery', () => {
const canonicalReads = keysReadBy(gitCleanEnv);
const localReads = keysReadBy(gitEnvironment);
expect(localReads).toStrictEqual(canonicalReads);
- const redirectKeys = [...canonicalReads].filter((key) => key.startsWith('GIT_'));
+ const redirectKeys = [
+ ...[...canonicalReads].filter((key) => key.startsWith('GIT_')),
+ 'GIT_CONFIG_KEY_0',
+ 'GIT_CONFIG_VALUE_0',
+ ];
const base = {
KEEP: 'yes',
LC_ALL: 'caller',
diff --git a/scripts/git-clean-env.mjs b/scripts/git-clean-env.mjs
index 521478273..b39d641a3 100644
--- a/scripts/git-clean-env.mjs
+++ b/scripts/git-clean-env.mjs
@@ -1,3 +1,5 @@
+const INDEXED_CONFIG_ENTRY = /^GIT_CONFIG_(?:KEY|VALUE)_\d+$/;
+
export function gitCleanEnv(base = process.env) {
const {
GIT_DIR: _d,
@@ -10,7 +12,9 @@ export function gitCleanEnv(base = process.env) {
GIT_PREFIX: _p,
GIT_CEILING_DIRECTORIES: _cdirs,
GIT_DISCOVERY_ACROSS_FILESYSTEM: _dafs,
+ GIT_CONFIG_PARAMETERS: _cparams,
+ GIT_CONFIG_COUNT: _ccount,
...env
} = base;
- return env;
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !INDEXED_CONFIG_ENTRY.test(name)));
}