fix(tests): scrub GIT_* env vars leaking from the pre-commit hook into git-fixture tests
server/lib/update-check.js's execGit() and two test helpers (lanes-cli.test.js, update-check.test.js) shelled out to git with an explicit `cwd` but no `env` override. A parent git hook process (this repo's own .husky/pre-commit, which runs `npm run test:server`) sets GIT_DIR/GIT_INDEX_FILE in its own environment; those leak to every child process and take precedence over `cwd` for repo discovery, so every git command these tests ran against their throwaway tmp repos was silently redirected at the real repo running the hook instead — reproduced firsthand as four foreign "init"/"fixture" commits overwriting a worktree branch mid pre-commit run. Fixes it the same way server/lib/worktree.js already documented and did for its own git calls: strip the GIT_* vars before exec.
This commit is contained in:
@@ -45,9 +45,25 @@ const CLI = path.join(__dirname, "..", "..", "bin", "ccam.js");
|
||||
let server;
|
||||
let BASE;
|
||||
|
||||
// Strip GIT_* vars a parent git hook (e.g. the pre-commit hook running this
|
||||
// very suite) sets in its own environment — those leak to every child
|
||||
// process and override an explicit `cwd`, so without this a git command
|
||||
// meant for this test's throwaway tmp repo silently operates on the real
|
||||
// repo running the hook instead.
|
||||
const GIT_ENV = { ...process.env };
|
||||
delete GIT_ENV.GIT_DIR;
|
||||
delete GIT_ENV.GIT_WORK_TREE;
|
||||
delete GIT_ENV.GIT_INDEX_FILE;
|
||||
delete GIT_ENV.GIT_COMMON_DIR;
|
||||
delete GIT_ENV.GIT_OBJECT_DIRECTORY;
|
||||
delete GIT_ENV.GIT_ALTERNATE_OBJECT_DIRECTORIES;
|
||||
delete GIT_ENV.GIT_PREFIX;
|
||||
delete GIT_ENV.GIT_NAMESPACE;
|
||||
delete GIT_ENV.GIT_CONFIG_PARAMETERS;
|
||||
|
||||
function git(args, cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn("git", args, { cwd });
|
||||
const child = spawn("git", args, { cwd, env: GIT_ENV });
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (chunk) => (stderr += chunk));
|
||||
child.on("error", reject);
|
||||
|
||||
Reference in New Issue
Block a user