Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(gates): the census is about the directory it runs in, not the one git pins

esengine2fae1e2b6fed
diff --git a/tools/lib/sourceCensus.mjs b/tools/lib/sourceCensus.mjs
index acfd9f6d5..bf989d7f3 100644
--- a/tools/lib/sourceCensus.mjs
+++ b/tools/lib/sourceCensus.mjs
@@ -25,8 +25,20 @@ export const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '
const CORPUS_KEY = 'estella-corpus';
const OURS = 'source';
+/**
+ * The environment a git command must run in to be ABOUT the directory it is run
+ * in. A hook exports GIT_DIR and friends, and they outrank `cwd`: unscrubbed, a
+ * submodule corpus comes back as the root's file list wearing the submodule's
+ * prefix — worse than the empty one this file exists to prevent.
+ */
+function unpinnedEnv() {
+ const env = { ...process.env };
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
+ return env;
+}
+
const git = (dir, args, max = 256 * 1024 * 1024) =>
- execFileSync('git', args, { cwd: dir, encoding: 'utf8', maxBuffer: max });
+ execFileSync('git', args, { cwd: dir, encoding: 'utf8', maxBuffer: max, env: unpinnedEnv() });
/**
* Every submodule `.gitmodules` declares, with the corpus it claims.
diff --git a/tools/tests/source-census.test.ts b/tools/tests/source-census.test.ts
index d42e6eee9..e97588f70 100644
--- a/tools/tests/source-census.test.ts
+++ b/tools/tests/source-census.test.ts
@@ -33,6 +33,24 @@ describe('the source census spans this repository and the submodules that hold o
expect(censusFindings(roots)).toEqual([]);
});
+ // A hook exports GIT_DIR, and it outranks `cwd`: unscrubbed, the submodule
+ // corpus is the ROOT's file list wearing the submodule's prefix — every path a
+ // lie, and only inside a push, which is the worst place to first meet it.
+ it('is about the directory it runs in even when git pins one from the environment', () => {
+ const editor = roots.find((r) => r.prefix === 'desktop')!;
+ if (!editor.present) return;
+ const before = process.env.GIT_DIR;
+ process.env.GIT_DIR = `${process.cwd()}/.git`;
+ try {
+ const files: string[] = trackedFiles(editor);
+ expect(files).toContain('desktop/package.json');
+ expect(files).not.toContain('desktop/sdk/package.json');
+ } finally {
+ if (before === undefined) delete process.env.GIT_DIR;
+ else process.env.GIT_DIR = before;
+ }
+ });
+
it('prefixes a submodule file so it names one path from the repo root', () => {
const editor = roots.find((r) => r.prefix === 'desktop')!;
const files: string[] = trackedFiles(editor);