test(lanes): scrub git hook env vars from lane-agents fixture, matching worktree.js's own git() helper

This commit is contained in:
2026-08-25 09:17:07 +07:00
parent 62789ffae7
commit 15c69334b5
+17 -1
View File
@@ -22,13 +22,29 @@ const { installAgents } = require("../lib/lane-agents");
after(() => fs.rmSync(SUITE_ROOT, { recursive: true, force: true }));
// 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 `git init` here
// operates on the outer repo's .git instead of this fixture's throwaway one.
// Same scrub `lanes-cli.test.js` and `worktree.js`'s own git() helper use.
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;
let laneSeq = 0;
/** Create a real git repo dir (used as a lane's cwd). */
function makeRepoDir() {
const cwd = path.join(SUITE_ROOT, `repo-${++laneSeq}`);
fs.mkdirSync(cwd, { recursive: true });
execFileSync("git", ["init", "--initial-branch=main"], { cwd, stdio: "pipe" });
execFileSync("git", ["init", "--initial-branch=main"], { cwd, stdio: "pipe", env: GIT_ENV });
return cwd;
}