* 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)
| 133 | * records its argv and cwd. The hook backgrounds the call, so poll for the log. |
| 134 | */ |
| 135 | function 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 | |
| 163 | describe('git sync hooks — project roots and existing hooks', () => { |
| 164 | let repo: string; |