MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / runHookWithFakeCodegraph

Function runHookWithFakeCodegraph

__tests__/git-hooks.test.ts:135–161  ·  view source on GitHub ↗

* Run a hook the way git does, with a fake `codegraph` first on PATH that * records its argv and cwd. The hook backgrounds the call, so poll for the log.

(hookFile: string, cwd: string)

Source from the content-addressed store, hash-verified

133 * records its argv and cwd. The hook backgrounds the call, so poll for the log.
134 */
135function runHookWithFakeCodegraph(hookFile: string, cwd: string): string[] {
136 const bin = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-fakebin-'));
137 const log = path.join(bin, 'calls.log');
138 try {
139 fs.writeFileSync(
140 path.join(bin, 'codegraph'),
141 `#!/bin/sh\necho "cwd=$(pwd) args=$*" >> '${log}'\n`,
142 { mode: 0o755 },
143 );
144 try {
145 execFileSync(hookFile, [], {
146 cwd,
147 stdio: 'ignore',
148 env: { ...process.env, PATH: `${bin}${path.delimiter}${process.env.PATH ?? ''}` },
149 });
150 } catch {
151 /* a hook that exits non-zero still ran; the log says what it did */
152 }
153 const deadline = Date.now() + 3000;
154 while (!fs.existsSync(log) && Date.now() < deadline) {
155 execFileSync('sleep', ['0.05']);
156 }
157 return fs.existsSync(log) ? fs.readFileSync(log, 'utf8').trim().split('\n') : [];
158 } finally {
159 fs.rmSync(bin, { recursive: true, force: true });
160 }
161}
162
163describe('git sync hooks — project roots and existing hooks', () => {
164 let repo: string;

Callers 1

git-hooks.test.tsFile · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected