install-lefthook.spec.ts 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. import { spawn, spawnSync } from 'node:child_process'
  2. import {
  3. chmodSync,
  4. existsSync,
  5. linkSync,
  6. mkdirSync,
  7. mkdtempSync,
  8. lstatSync,
  9. readFileSync,
  10. renameSync,
  11. rmSync,
  12. symlinkSync,
  13. writeFileSync,
  14. } from 'node:fs'
  15. import { tmpdir } from 'node:os'
  16. import { dirname, isAbsolute, join, resolve } from 'node:path'
  17. import { fileURLToPath } from 'node:url'
  18. import { afterEach, describe, expect, it } from 'vitest'
  19. import { removeFixtureSafely, unlinkFixtureLinks } from './test-fixture-cleanup.ts'
  20. const installer = fileURLToPath(new URL('./install-lefthook.mjs', import.meta.url))
  21. const pairingMergeDriver = 'scripts/merge-translation-pairing-driver.sh %O %A %B %P'
  22. const scriptsDirectory = fileURLToPath(new URL('.', import.meta.url))
  23. const tsxPackageDirectory = dirname(fileURLToPath(import.meta.resolve('tsx/package.json')))
  24. const fixtures: string[] = []
  25. interface Fixture {
  26. container: string
  27. env: NodeJS.ProcessEnv
  28. linked: string
  29. main: string
  30. }
  31. interface CommandResult {
  32. status: number | null
  33. stderr: string
  34. stdout: string
  35. }
  36. afterEach(() => {
  37. for (const fixture of fixtures.splice(0)) removeFixtureSafely(fixture)
  38. })
  39. function commandResult(command: string, args: string[], cwd: string, env: NodeJS.ProcessEnv): CommandResult {
  40. const result = spawnSync(command, args, { cwd, encoding: 'utf8', env })
  41. return { status: result.status, stderr: result.stderr, stdout: result.stdout }
  42. }
  43. function gitResult(fixture: Fixture, cwd: string, args: string[]): CommandResult {
  44. return commandResult('git', args, cwd, fixture.env)
  45. }
  46. function git(fixture: Fixture, cwd: string, args: string[]): string {
  47. const result = gitResult(fixture, cwd, args)
  48. if (result.status !== 0) {
  49. throw new Error(`git ${args.join(' ')} failed: ${result.stderr}`)
  50. }
  51. return result.stdout.trim()
  52. }
  53. function write(path: string, content: string, mode?: number): void {
  54. mkdirSync(dirname(path), { recursive: true })
  55. writeFileSync(path, content, mode === undefined ? undefined : { mode })
  56. }
  57. function fakeLefthookSource(): string {
  58. return `#!/usr/bin/env node
  59. import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
  60. import { execFileSync } from 'node:child_process'
  61. import { join } from 'node:path'
  62. if (process.argv.slice(2).join(' ') !== 'install --force') process.exit(64)
  63. const rootOutput = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' })
  64. const root = rootOutput.endsWith('\\n') ? rootOutput.slice(0, -1) : rootOutput
  65. const forbiddenConfigKey = process.env.DSH_TEST_FORBIDDEN_GIT_CONFIG_KEY
  66. if (forbiddenConfigKey !== undefined) {
  67. try {
  68. execFileSync('git', ['config', '--get', forbiddenConfigKey], { encoding: 'utf8' })
  69. process.exit(92)
  70. } catch (error) {
  71. if (error === null || typeof error !== 'object' || !('status' in error) || error.status !== 1) throw error
  72. }
  73. }
  74. const hooksPath = execFileSync('git', ['config', '--get', 'core.hooksPath'], { encoding: 'utf8' }).trim()
  75. mkdirSync(hooksPath, { recursive: true })
  76. const running = join(hooksPath, '.fake-lefthook-running')
  77. try {
  78. writeFileSync(running, String(process.pid), { flag: 'wx' })
  79. } catch {
  80. process.exit(91)
  81. }
  82. const delay = Number(process.env.DSH_TEST_LEFTHOOK_DELAY_MS ?? 0)
  83. if (delay > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay)
  84. const replaceLockPath = process.env.DSH_TEST_LEFTHOOK_REPLACE_LOCK_PATH
  85. if (replaceLockPath !== undefined) writeFileSync(replaceLockPath, 'replacement owner\\n')
  86. const shouldFail = process.env.DSH_TEST_LEFTHOOK_FAIL === '1'
  87. if (!shouldFail) {
  88. const binary = join(root, 'node_modules', '.bin', process.platform === 'win32' ? 'lefthook.cmd' : 'lefthook')
  89. const config = readFileSync(join(root, 'lefthook.yml'), 'utf8').trim()
  90. const hook = \`#!/bin/sh\\n# root=\${root}\\n# binary=\${binary}\\n# config=\${config}\\nexit 0\\n\`
  91. for (const name of ['pre-commit', 'pre-merge-commit', 'pre-push']) writeFileSync(join(hooksPath, name), hook, { mode: 0o755 })
  92. }
  93. if (existsSync(running)) unlinkSync(running)
  94. if (process.env.DSH_TEST_LEFTHOOK_BREAK_WORKTREE_CONFIG === '1') {
  95. const configPath = execFileSync('git', ['rev-parse', '--git-path', 'config.worktree'], { encoding: 'utf8' }).trim()
  96. writeFileSync(configPath, '[invalid\\n')
  97. }
  98. if (shouldFail) process.exit(77)
  99. `
  100. }
  101. function installFakeLefthook(root: string): void {
  102. const binDirectory = join(root, 'node_modules/.bin')
  103. mkdirSync(binDirectory, { recursive: true })
  104. writeFileSync(join(binDirectory, 'fake-lefthook.mjs'), fakeLefthookSource())
  105. if (process.platform === 'win32') {
  106. writeFileSync(
  107. join(binDirectory, 'lefthook.cmd'),
  108. `@echo off\r\n"${process.execPath}" "%~dp0\\fake-lefthook.mjs" %*\r\n`,
  109. )
  110. return
  111. }
  112. const shim = join(binDirectory, 'lefthook')
  113. writeFileSync(shim, `#!/bin/sh\nexec "${process.execPath}" "$(dirname "$0")/fake-lefthook.mjs" "$@"\n`)
  114. chmodSync(shim, 0o755)
  115. }
  116. function installPairingProbeFixture(root: string): void {
  117. const linkType = process.platform === 'win32' ? 'junction' : 'dir'
  118. symlinkSync(scriptsDirectory, join(root, 'scripts'), linkType)
  119. symlinkSync(tsxPackageDirectory, join(root, 'node_modules/tsx'), linkType)
  120. }
  121. function createFixture(names: { main?: string; linked?: string } = {}): Fixture {
  122. const container = mkdtempSync(join(tmpdir(), 'dsh-lefthook-'))
  123. fixtures.push(container)
  124. const main = join(container, names.main ?? 'main')
  125. const linked = join(container, names.linked ?? 'linked')
  126. const env: NodeJS.ProcessEnv = {
  127. ...process.env,
  128. CI: 'false',
  129. GITHUB_ACTIONS: 'false',
  130. GIT_AUTHOR_EMAIL: 'hooks@example.test',
  131. GIT_AUTHOR_NAME: 'Hooks Test',
  132. GIT_COMMITTER_EMAIL: 'hooks@example.test',
  133. GIT_COMMITTER_NAME: 'Hooks Test',
  134. GIT_CONFIG_GLOBAL: join(container, 'global.gitconfig'),
  135. GIT_CONFIG_NOSYSTEM: '1',
  136. HOME: container,
  137. XDG_CONFIG_HOME: join(container, '.config'),
  138. }
  139. const fixture = { container, env, linked, main }
  140. mkdirSync(main)
  141. git(fixture, container, ['init', main])
  142. write(join(main, 'README.md'), '# fixture\n')
  143. git(fixture, main, ['add', 'README.md'])
  144. git(fixture, main, ['commit', '-m', 'fixture'])
  145. git(fixture, main, ['worktree', 'add', '-b', 'linked', linked])
  146. write(join(main, 'lefthook.yml'), 'main-worktree-config\n')
  147. write(join(linked, 'lefthook.yml'), 'linked-worktree-config\n')
  148. installFakeLefthook(main)
  149. installFakeLefthook(linked)
  150. installPairingProbeFixture(main)
  151. installPairingProbeFixture(linked)
  152. return fixture
  153. }
  154. function gitDirectory(fixture: Fixture, root: string): string {
  155. return git(fixture, root, ['rev-parse', '--absolute-git-dir'])
  156. }
  157. function commonDirectory(fixture: Fixture): string {
  158. const output = git(fixture, fixture.main, ['rev-parse', '--git-common-dir'])
  159. return isAbsolute(output) ? output : resolve(fixture.main, output)
  160. }
  161. function hooksPath(fixture: Fixture, root: string): string {
  162. return join(gitDirectory(fixture, root), 'dsh-hooks')
  163. }
  164. function installLockPath(fixture: Fixture): string {
  165. return join(commonDirectory(fixture), 'dsh-lefthook-install.lock')
  166. }
  167. async function waitForPath(path: string): Promise<void> {
  168. const deadline = Date.now() + 10_000
  169. while (!existsSync(path)) {
  170. if (Date.now() >= deadline) throw new Error(`timed out waiting for ${path}`)
  171. await new Promise(resolveWait => setTimeout(resolveWait, 10))
  172. }
  173. }
  174. function runInstaller(
  175. fixture: Fixture,
  176. root: string,
  177. extraEnv: NodeJS.ProcessEnv = {},
  178. ): Promise<CommandResult> {
  179. return new Promise((resolveResult, reject) => {
  180. const child = spawn(process.execPath, [installer], {
  181. cwd: root,
  182. env: { ...fixture.env, ...extraEnv },
  183. stdio: ['ignore', 'pipe', 'pipe'],
  184. })
  185. let stdout = ''
  186. let stderr = ''
  187. child.stdout.on('data', (chunk: Buffer) => { stdout += chunk.toString() })
  188. child.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString() })
  189. child.on('error', reject)
  190. child.on('close', (status) => { resolveResult({ status, stderr, stdout }) })
  191. })
  192. }
  193. // Every case builds scratch worktrees and drives them through spawned Git and
  194. // Node subprocesses, so the suite is bound by process creation rather than by
  195. // its assertions. The value matches DSH_COVERAGE_TEST_TIMEOUT_MS, which the
  196. // Windows coverage lane passes as --testTimeout: a describe value overrides that
  197. // flag rather than yielding to it, so a smaller one here lowers what the lane
  198. // grants every case in this file, none of which carries an allowance of its own.
  199. // Rationale and the paired hook budget are in
  200. // .agents/notes/archived/testing/2026-08-29-windows-lane-hook-and-lefthook-budget.md.
  201. describe('worktree-local Lefthook installer', { timeout: 90_000 }, () => {
  202. for (const [label, extraEnv] of [
  203. ['CI', { CI: 'true' }],
  204. ['GitHub Actions', { GITHUB_ACTIONS: 'true' }],
  205. ] satisfies [string, NodeJS.ProcessEnv][]) {
  206. it(`skips hook installation when ${label} marks an automated job`, async () => {
  207. const fixture = createFixture()
  208. const common = commonDirectory(fixture)
  209. const missingInclude = join(fixture.container, 'missing-ci-credentials.gitconfig')
  210. git(fixture, fixture.main, [
  211. 'config',
  212. '--local',
  213. 'includeIf.gitdir:/github/workspace/.git.path',
  214. missingInclude,
  215. ])
  216. const result = await runInstaller(fixture, fixture.main, extraEnv)
  217. expect(result.status, result.stderr).toBe(0)
  218. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  219. expect(git(fixture, fixture.main, ['config', '--get', 'core.repositoryFormatVersion'])).toBe('0')
  220. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  221. expect(existsSync(join(common, 'config.worktree'))).toBe(false)
  222. expect(gitResult(fixture, fixture.main, [
  223. 'config', '--get', 'merge.dsh-translation-pairing.driver',
  224. ]).status).toBe(1)
  225. })
  226. }
  227. it('isolates main and linked worktrees without changing legacy common hooks', async () => {
  228. const fixture = createFixture()
  229. const common = commonDirectory(fixture)
  230. const legacyHook = join(common, 'hooks/pre-commit')
  231. write(legacyHook, '#!/bin/sh\n# legacy hook\n', 0o755)
  232. const mainInstall = await runInstaller(fixture, fixture.main)
  233. const linkedInstall = await runInstaller(fixture, fixture.linked)
  234. expect(mainInstall.status, mainInstall.stderr).toBe(0)
  235. expect(linkedInstall.status, linkedInstall.stderr).toBe(0)
  236. const mainHooks = hooksPath(fixture, fixture.main)
  237. const linkedHooks = hooksPath(fixture, fixture.linked)
  238. expect(mainHooks).not.toBe(linkedHooks)
  239. expect(git(fixture, fixture.main, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(mainHooks)
  240. expect(git(fixture, fixture.linked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(linkedHooks)
  241. expect(git(fixture, fixture.main, [
  242. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.driver',
  243. ])).toBe(pairingMergeDriver)
  244. expect(git(fixture, fixture.linked, [
  245. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.driver',
  246. ])).toBe(pairingMergeDriver)
  247. const mainHook = readFileSync(join(mainHooks, 'pre-commit'), 'utf8')
  248. const linkedHook = readFileSync(join(linkedHooks, 'pre-commit'), 'utf8')
  249. const canonicalMain = git(fixture, fixture.main, ['rev-parse', '--show-toplevel'])
  250. const canonicalLinked = git(fixture, fixture.linked, ['rev-parse', '--show-toplevel'])
  251. expect(mainHook).toContain(`# root=${canonicalMain}`)
  252. expect(mainHook).toContain('# config=main-worktree-config')
  253. expect(mainHook).not.toContain(canonicalLinked)
  254. expect(linkedHook).toContain(`# root=${canonicalLinked}`)
  255. expect(linkedHook).toContain('# config=linked-worktree-config')
  256. expect(linkedHook).not.toContain(canonicalMain)
  257. expect(existsSync(join(mainHooks, 'pre-merge-commit'))).toBe(true)
  258. expect(existsSync(join(linkedHooks, 'pre-merge-commit'))).toBe(true)
  259. expect(readFileSync(legacyHook, 'utf8')).toBe('#!/bin/sh\n# legacy hook\n')
  260. const commonConfig = join(common, 'config')
  261. expect(git(fixture, fixture.main, ['config', '--file', commonConfig, '--get', 'core.repositoryFormatVersion'])).toBe('1')
  262. expect(git(fixture, fixture.main, ['config', '--file', commonConfig, '--get', 'extensions.worktreeConfig'])).toBe('true')
  263. expect(gitResult(fixture, fixture.main, ['config', '--file', commonConfig, '--get', 'core.bare']).status).toBe(1)
  264. const mainHookBeforeRemoval = readFileSync(join(mainHooks, 'pre-commit'), 'utf8')
  265. // Windows Git follows the fixture's MOUNT_POINT junctions into their real
  266. // targets while removing a worktree; unlink them first so the removal
  267. // cannot delete the repository's scripts/ or tsx package.
  268. unlinkFixtureLinks(fixture.linked)
  269. git(fixture, fixture.main, ['worktree', 'remove', '--force', fixture.linked])
  270. expect(readFileSync(join(mainHooks, 'pre-commit'), 'utf8')).toBe(mainHookBeforeRemoval)
  271. expect(readFileSync(legacyHook, 'utf8')).toBe('#!/bin/sh\n# legacy hook\n')
  272. })
  273. it('replaces the owned hook path Git copies into a newly added worktree', async () => {
  274. const fixture = createFixture()
  275. const mainInstall = await runInstaller(fixture, fixture.main)
  276. expect(mainInstall.status, mainInstall.stderr).toBe(0)
  277. const mainHooks = hooksPath(fixture, fixture.main)
  278. const mainHookBefore = readFileSync(join(mainHooks, 'pre-commit'), 'utf8')
  279. const lateLinked = join(fixture.container, 'late-linked')
  280. git(fixture, fixture.main, ['worktree', 'add', '-b', 'late-linked', lateLinked])
  281. write(join(lateLinked, 'lefthook.yml'), 'late-linked-worktree-config\n')
  282. installFakeLefthook(lateLinked)
  283. installPairingProbeFixture(lateLinked)
  284. expect(git(fixture, lateLinked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(mainHooks)
  285. const linkedInstall = await runInstaller(fixture, lateLinked)
  286. expect(linkedInstall.status, linkedInstall.stderr).toBe(0)
  287. const linkedHooks = hooksPath(fixture, lateLinked)
  288. expect(linkedHooks).not.toBe(mainHooks)
  289. expect(git(fixture, lateLinked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(linkedHooks)
  290. expect(readFileSync(join(linkedHooks, 'pre-commit'), 'utf8')).toContain(
  291. '# config=late-linked-worktree-config',
  292. )
  293. expect(readFileSync(join(mainHooks, 'pre-commit'), 'utf8')).toBe(mainHookBefore)
  294. })
  295. it('serializes concurrent installs and keeps repeated output stable', async () => {
  296. const fixture = createFixture()
  297. const delayed = { DSH_TEST_LEFTHOOK_DELAY_MS: '150' }
  298. const first = await Promise.all([
  299. runInstaller(fixture, fixture.main, delayed),
  300. runInstaller(fixture, fixture.linked, delayed),
  301. ])
  302. for (const result of first) expect(result.status, result.stderr).toBe(0)
  303. const mainHookPath = join(hooksPath(fixture, fixture.main), 'pre-push')
  304. const initialHook = readFileSync(mainHookPath, 'utf8')
  305. const repeated = await Promise.all([
  306. runInstaller(fixture, fixture.main, delayed),
  307. runInstaller(fixture, fixture.main, delayed),
  308. ])
  309. for (const result of repeated) expect(result.status, result.stderr).toBe(0)
  310. expect(readFileSync(mainHookPath, 'utf8')).toBe(initialHook)
  311. expect(existsSync(join(commonDirectory(fixture), 'dsh-lefthook-install.lock'))).toBe(false)
  312. expect(existsSync(join(hooksPath(fixture, fixture.main), '.fake-lefthook-running'))).toBe(false)
  313. })
  314. it('waits for a concurrent installer to finish publishing its lock record', async () => {
  315. const fixture = createFixture()
  316. const lockPath = installLockPath(fixture)
  317. const publishing = runInstaller(fixture, fixture.main, {
  318. DSH_TEST_LEFTHOOK_LOCK_WRITE_DELAY_MS: '200',
  319. })
  320. await waitForPath(lockPath)
  321. expect(readFileSync(lockPath, 'utf8')).toBe('')
  322. const waiting = runInstaller(fixture, fixture.linked)
  323. const results = await Promise.all([publishing, waiting])
  324. for (const result of results) expect(result.status, result.stderr).toBe(0)
  325. expect(existsSync(lockPath)).toBe(false)
  326. })
  327. it('repairs its owned absolute hook path after the checkout moves', async () => {
  328. const fixture = createFixture()
  329. const oldRoot = fixture.main
  330. const first = await runInstaller(fixture, oldRoot)
  331. expect(first.status, first.stderr).toBe(0)
  332. const oldHooks = hooksPath(fixture, oldRoot)
  333. const movedRoot = join(fixture.container, 'moved-main')
  334. renameSync(oldRoot, movedRoot)
  335. const moved = await runInstaller(fixture, movedRoot)
  336. expect(moved.status, moved.stderr).toBe(0)
  337. const movedHooks = hooksPath(fixture, movedRoot)
  338. expect(movedHooks).not.toBe(oldHooks)
  339. expect(git(fixture, movedRoot, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(movedHooks)
  340. const canonicalMoved = git(fixture, movedRoot, ['rev-parse', '--show-toplevel'])
  341. expect(readFileSync(join(movedHooks, 'pre-commit'), 'utf8')).toContain(`# root=${canonicalMoved}`)
  342. expect(readFileSync(join(movedHooks, '.dsh-lefthook-owned'), 'utf8')).toContain(
  343. JSON.stringify(movedHooks),
  344. )
  345. })
  346. it.skipIf(process.platform === 'win32')('refuses a multiply linked ownership marker before relocation rewrites it', async () => {
  347. const fixture = createFixture()
  348. const oldRoot = fixture.main
  349. const first = await runInstaller(fixture, oldRoot)
  350. expect(first.status, first.stderr).toBe(0)
  351. const oldHooks = hooksPath(fixture, oldRoot)
  352. const markerName = '.dsh-lefthook-owned'
  353. const externalMarker = join(fixture.container, 'external-marker')
  354. linkSync(join(oldHooks, markerName), externalMarker)
  355. const externalContent = readFileSync(externalMarker, 'utf8')
  356. const movedRoot = join(fixture.container, 'moved-main')
  357. renameSync(oldRoot, movedRoot)
  358. const result = await runInstaller(fixture, movedRoot)
  359. expect(result.status).toBe(1)
  360. expect(result.stderr).toContain('invalid ownership marker')
  361. expect(readFileSync(externalMarker, 'utf8')).toBe(externalContent)
  362. })
  363. it.skipIf(process.platform === 'win32')('refuses aliased generated hooks before Lefthook can overwrite their targets', async () => {
  364. for (const kind of ['symlink', 'hardlink'] as const) {
  365. const fixture = createFixture()
  366. const first = await runInstaller(fixture, fixture.main)
  367. expect(first.status, first.stderr).toBe(0)
  368. const hook = join(hooksPath(fixture, fixture.main), 'pre-commit')
  369. const externalHook = join(fixture.container, `${kind}-external-hook`)
  370. rmSync(hook)
  371. write(externalHook, `external ${kind} target\n`)
  372. if (kind === 'symlink') symlinkSync(externalHook, hook)
  373. else linkSync(externalHook, hook)
  374. const externalContent = readFileSync(externalHook, 'utf8')
  375. const result = await runInstaller(fixture, fixture.main)
  376. expect(result.status).toBe(1)
  377. expect(result.stderr).toContain('non-regular or multiply linked hook entry')
  378. expect(readFileSync(externalHook, 'utf8')).toBe(externalContent)
  379. }
  380. })
  381. it('restores the marker-backed stale hook path when relocation reinstall fails', async () => {
  382. const fixture = createFixture()
  383. const oldRoot = fixture.main
  384. const first = await runInstaller(fixture, oldRoot)
  385. expect(first.status, first.stderr).toBe(0)
  386. const oldHooks = hooksPath(fixture, oldRoot)
  387. const markerName = '.dsh-lefthook-owned'
  388. const previousMarker = readFileSync(join(oldHooks, markerName), 'utf8')
  389. const movedRoot = join(fixture.container, 'moved-main')
  390. renameSync(oldRoot, movedRoot)
  391. const failed = await runInstaller(fixture, movedRoot, { DSH_TEST_LEFTHOOK_FAIL: '1' })
  392. expect(failed.status).toBe(1)
  393. expect(failed.stderr).toContain('exit status 77')
  394. const movedHooks = hooksPath(fixture, movedRoot)
  395. expect(git(fixture, movedRoot, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(oldHooks)
  396. expect(readFileSync(join(movedHooks, markerName), 'utf8')).toBe(previousMarker)
  397. })
  398. it('refuses dormant repository extensions before upgrading the repository format', async () => {
  399. const fixture = createFixture()
  400. const commonConfig = join(commonDirectory(fixture), 'config')
  401. git(fixture, fixture.main, ['config', 'extensions.dshUnknown', 'true'])
  402. expect(gitResult(fixture, fixture.main, ['status', '--porcelain']).status).toBe(0)
  403. const result = await runInstaller(fixture, fixture.main)
  404. expect(result.status).toBe(1)
  405. expect(result.stderr).toContain('dormant repository extension extensions.dshunknown')
  406. expect(git(fixture, fixture.main, [
  407. 'config', '--file', commonConfig, '--get', 'core.repositoryFormatVersion',
  408. ])).toBe('0')
  409. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  410. expect(gitResult(fixture, fixture.main, ['status', '--porcelain']).status).toBe(0)
  411. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  412. })
  413. it('refuses direct core.worktree before enabling worktree config', async () => {
  414. const fixture = createFixture()
  415. const commonConfig = join(commonDirectory(fixture), 'config')
  416. git(fixture, fixture.main, ['config', '--file', commonConfig, 'core.worktree', fixture.main])
  417. const result = await runInstaller(fixture, fixture.linked)
  418. expect(result.status).toBe(1)
  419. expect(result.stderr).toContain('core.worktree is in the common config')
  420. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  421. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  422. })
  423. it.skipIf(process.platform === 'win32')('refuses a symlinked common repository config before writing through it', async () => {
  424. const fixture = createFixture()
  425. const commonConfig = join(commonDirectory(fixture), 'config')
  426. const externalConfig = join(fixture.container, 'external-common.gitconfig')
  427. renameSync(commonConfig, externalConfig)
  428. symlinkSync(externalConfig, commonConfig)
  429. const externalContent = readFileSync(externalConfig, 'utf8')
  430. const result = await runInstaller(fixture, fixture.main)
  431. expect(result.status).toBe(1)
  432. expect(result.stderr).toContain('common repository config')
  433. expect(result.stderr).toContain('not a regular file')
  434. expect(lstatSync(commonConfig).isSymbolicLink()).toBe(true)
  435. expect(readFileSync(externalConfig, 'utf8')).toBe(externalContent)
  436. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  437. })
  438. it('leaves stale installer locks for explicit recovery', async () => {
  439. const fixture = createFixture()
  440. const lockPath = installLockPath(fixture)
  441. const completed = spawnSync(process.execPath, ['-e', ''])
  442. expect(completed.status).toBe(0)
  443. const staleRecord = `${String(completed.pid)} 00000000-0000-4000-8000-000000000000\n`
  444. writeFileSync(lockPath, staleRecord)
  445. const results = await Promise.all(Array.from(
  446. { length: 4 },
  447. () => runInstaller(fixture, fixture.main),
  448. ))
  449. for (const result of results) {
  450. expect(result.status).toBe(1)
  451. expect(result.stderr).toContain('stale Lefthook installer lock')
  452. expect(result.stderr).toContain('remove it manually')
  453. }
  454. expect(readFileSync(lockPath, 'utf8')).toBe(staleRecord)
  455. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  456. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  457. })
  458. it('leaves invalid installer locks for explicit recovery', async () => {
  459. const fixture = createFixture()
  460. const lockPath = installLockPath(fixture)
  461. const invalidRecord = 'not an installer lock\n'
  462. writeFileSync(lockPath, invalidRecord)
  463. const result = await runInstaller(fixture, fixture.main)
  464. expect(result.status).toBe(1)
  465. expect(result.stderr).toContain('invalid Lefthook installer lock')
  466. expect(result.stderr).toContain('remove it manually')
  467. expect(readFileSync(lockPath, 'utf8')).toBe(invalidRecord)
  468. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  469. })
  470. it('does not release an installer lock whose ownership changed', async () => {
  471. const fixture = createFixture()
  472. const lockPath = installLockPath(fixture)
  473. // The fake child replaces the record while the installer holds the lock.
  474. const result = await runInstaller(fixture, fixture.main, {
  475. DSH_TEST_LEFTHOOK_REPLACE_LOCK_PATH: lockPath,
  476. })
  477. expect(result.status).toBe(1)
  478. expect(result.stderr).toContain('installer lock ownership changed')
  479. expect(readFileSync(lockPath, 'utf8')).toBe('replacement owner\n')
  480. })
  481. it.skipIf(process.platform === 'win32')('preserves trailing spaces in worktree paths', async () => {
  482. const fixture = createFixture({ main: 'main ', linked: 'linked ' })
  483. for (const root of [fixture.main, fixture.linked]) {
  484. const result = await runInstaller(fixture, root)
  485. expect(result.status, result.stderr).toBe(0)
  486. expect(git(fixture, root, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(hooksPath(fixture, root))
  487. }
  488. })
  489. it('preserves user-owned hook paths unless an inherited value is explicitly overridden', async () => {
  490. const fixture = createFixture()
  491. const customHook = join(fixture.main, 'custom-hooks/pre-commit')
  492. write(customHook, '#!/bin/sh\n# custom hook\n', 0o755)
  493. git(fixture, fixture.main, ['config', 'core.hooksPath', 'custom-hooks'])
  494. const refused = await runInstaller(fixture, fixture.main)
  495. expect(refused.status).toBe(1)
  496. expect(refused.stderr).toContain('refusing to replace user-owned core.hooksPath')
  497. expect(refused.stderr).toContain('DSH_LEFTHOOK_ALLOW_HOOKS_PATH_OVERRIDE=1')
  498. expect(git(fixture, fixture.main, ['config', '--get', 'core.hooksPath'])).toBe('custom-hooks')
  499. expect(readFileSync(customHook, 'utf8')).toBe('#!/bin/sh\n# custom hook\n')
  500. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  501. const optedIn = await runInstaller(fixture, fixture.main, {
  502. DSH_LEFTHOOK_ALLOW_HOOKS_PATH_OVERRIDE: '1',
  503. })
  504. expect(optedIn.status, optedIn.stderr).toBe(0)
  505. expect(git(fixture, fixture.main, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(hooksPath(fixture, fixture.main))
  506. expect(git(fixture, fixture.linked, ['config', '--get', 'core.hooksPath'])).toBe('custom-hooks')
  507. expect(gitResult(fixture, fixture.linked, ['config', '--worktree', '--get', 'core.hooksPath']).status).toBe(1)
  508. expect(readFileSync(customHook, 'utf8')).toBe('#!/bin/sh\n# custom hook\n')
  509. git(fixture, fixture.linked, ['config', '--worktree', 'core.hooksPath', 'linked-custom-hooks'])
  510. const explicitWorktreePath = await runInstaller(fixture, fixture.linked, {
  511. DSH_LEFTHOOK_ALLOW_HOOKS_PATH_OVERRIDE: '1',
  512. })
  513. expect(explicitWorktreePath.status).toBe(1)
  514. expect(git(fixture, fixture.linked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe('linked-custom-hooks')
  515. })
  516. it('does not trust an ownership marker outside a registered worktree hook path', async () => {
  517. const fixture = createFixture()
  518. const mainInstall = await runInstaller(fixture, fixture.main)
  519. expect(mainInstall.status, mainInstall.stderr).toBe(0)
  520. const externalHooks = join(fixture.container, 'external-owned-hooks')
  521. write(
  522. join(externalHooks, '.dsh-lefthook-owned'),
  523. `${JSON.stringify({
  524. version: 1,
  525. owner: 'deepseek-harness worktree-local lefthook hooks',
  526. hooksPath: externalHooks,
  527. })}\n`,
  528. 0o600,
  529. )
  530. git(fixture, fixture.linked, ['config', '--worktree', 'core.hooksPath', externalHooks])
  531. const result = await runInstaller(fixture, fixture.linked)
  532. expect(result.status).toBe(1)
  533. expect(result.stderr).toContain('worktree-scoped core.hooksPath')
  534. expect(git(fixture, fixture.linked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(externalHooks)
  535. expect(existsSync(hooksPath(fixture, fixture.linked))).toBe(false)
  536. })
  537. it('refuses to activate a sibling worktree dormant hook path', async () => {
  538. const fixture = createFixture()
  539. const linkedConfig = join(gitDirectory(fixture, fixture.linked), 'config.worktree')
  540. const linkedHooks = join(fixture.linked, 'custom-hooks')
  541. git(fixture, fixture.main, ['config', '--file', linkedConfig, 'core.hooksPath', linkedHooks])
  542. expect(gitResult(fixture, fixture.linked, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  543. const result = await runInstaller(fixture, fixture.main)
  544. expect(result.status).toBe(1)
  545. expect(result.stderr).toContain('sibling dormant worktree config')
  546. expect(result.stderr).toContain(JSON.stringify(linkedConfig))
  547. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  548. expect(gitResult(fixture, fixture.linked, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  549. expect(git(fixture, fixture.main, ['config', '--file', linkedConfig, '--get', 'core.hooksPath'])).toBe(linkedHooks)
  550. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  551. })
  552. it.skipIf(process.platform === 'win32')('refuses an active symlinked worktree config before writing through it', async () => {
  553. const fixture = createFixture()
  554. const commonConfig = join(commonDirectory(fixture), 'config')
  555. const worktreeConfig = join(gitDirectory(fixture, fixture.main), 'config.worktree')
  556. const externalConfig = join(fixture.container, 'external.gitconfig')
  557. const externalContent = '[user]\n\tname = External owner\n'
  558. write(externalConfig, externalContent)
  559. git(fixture, fixture.main, ['config', '--file', commonConfig, 'core.repositoryFormatVersion', '1'])
  560. git(fixture, fixture.main, ['config', '--file', commonConfig, 'extensions.worktreeConfig', 'true'])
  561. symlinkSync(externalConfig, worktreeConfig)
  562. const result = await runInstaller(fixture, fixture.main)
  563. expect(result.status).toBe(1)
  564. expect(result.stderr).toContain('active worktree config')
  565. expect(result.stderr).toContain('not a regular file')
  566. expect(lstatSync(worktreeConfig).isSymbolicLink()).toBe(true)
  567. expect(readFileSync(externalConfig, 'utf8')).toBe(externalContent)
  568. expect(gitResult(fixture, fixture.main, [
  569. 'config', '--file', externalConfig, '--get', 'core.hooksPath',
  570. ]).status).toBe(1)
  571. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  572. })
  573. for (const includeKey of ['include.path', 'includeIf.onbranch:conditional.path']) {
  574. for (const key of ['core.worktree', 'core.bare', 'extensions.dshunknown']) {
  575. it(`ignores ${key} loaded through ${includeKey}`, async () => {
  576. const fixture = createFixture()
  577. const commonConfig = join(commonDirectory(fixture), 'config')
  578. const includedConfig = join(fixture.container, `${includeKey.split('.')[0]}-${key.replace('.', '-')}.gitconfig`)
  579. const value = key === 'core.worktree' ? fixture.main : 'true'
  580. git(fixture, fixture.main, ['config', '--file', includedConfig, key, value])
  581. git(fixture, fixture.main, ['config', '--file', commonConfig, includeKey, includedConfig])
  582. const result = await runInstaller(fixture, fixture.linked)
  583. expect(result.status, result.stderr).toBe(0)
  584. expect(git(fixture, fixture.linked, ['config', '--worktree', '--get', 'core.hooksPath'])).toBe(
  585. hooksPath(fixture, fixture.linked),
  586. )
  587. expect(existsSync(join(hooksPath(fixture, fixture.linked), 'pre-commit'))).toBe(true)
  588. })
  589. }
  590. }
  591. it('ignores an inactive global includeIf that provides a hook path for another repository', async () => {
  592. const fixture = createFixture()
  593. const globalConfig = fixture.env.GIT_CONFIG_GLOBAL
  594. if (globalConfig === undefined) throw new Error('fixture global config path is missing')
  595. const includedConfig = join(fixture.container, 'other-repository.gitconfig')
  596. const includedHooks = join(fixture.container, 'other-repository-hooks')
  597. git(fixture, fixture.main, ['config', '--file', includedConfig, 'core.hooksPath', includedHooks])
  598. git(fixture, fixture.main, [
  599. 'config',
  600. '--file',
  601. globalConfig,
  602. `includeIf.gitdir:${join(fixture.container, 'other')}/.path`,
  603. includedConfig,
  604. ])
  605. const result = await runInstaller(fixture, fixture.linked)
  606. expect(result.status, result.stderr).toBe(0)
  607. expect(git(fixture, fixture.linked, ['config', '--get', 'core.hooksPath'])).toBe(hooksPath(fixture, fixture.linked))
  608. })
  609. it('never overrides a command-scoped hook path', async () => {
  610. const fixture = createFixture()
  611. const commandHooks = join(fixture.container, 'command-hooks')
  612. const sentinel = join(commandHooks, 'pre-commit')
  613. write(sentinel, '#!/bin/sh\n# command-scope sentinel\n', 0o755)
  614. const result = await runInstaller(fixture, fixture.main, {
  615. DSH_LEFTHOOK_ALLOW_HOOKS_PATH_OVERRIDE: '1',
  616. GIT_CONFIG_COUNT: '1',
  617. GIT_CONFIG_KEY_0: 'core.hooksPath',
  618. GIT_CONFIG_VALUE_0: commandHooks,
  619. })
  620. expect(result.status).toBe(1)
  621. expect(result.stderr).toContain('command-scoped core.hooksPath')
  622. expect(readFileSync(sentinel, 'utf8')).toBe('#!/bin/sh\n# command-scope sentinel\n')
  623. expect(gitResult(fixture, fixture.main, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  624. expect(gitResult(fixture, fixture.main, [
  625. 'config', '--get', 'merge.dsh-translation-pairing.driver',
  626. ]).status).toBe(1)
  627. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  628. })
  629. it('never replaces a custom worktree pairing merge driver', async () => {
  630. const fixture = createFixture()
  631. const commonConfig = join(commonDirectory(fixture), 'config')
  632. git(fixture, fixture.main, ['config', '--file', commonConfig, 'core.repositoryFormatVersion', '1'])
  633. git(fixture, fixture.main, ['config', '--file', commonConfig, 'extensions.worktreeConfig', 'true'])
  634. git(fixture, fixture.main, [
  635. 'config', '--worktree', 'merge.dsh-translation-pairing.driver', 'custom-driver %A',
  636. ])
  637. const result = await runInstaller(fixture, fixture.main)
  638. expect(result.status).toBe(1)
  639. expect(result.stderr).toContain('refusing to replace worktree merge.dsh-translation-pairing.driver')
  640. expect(git(fixture, fixture.main, [
  641. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.driver',
  642. ])).toBe('custom-driver %A')
  643. expect(gitResult(fixture, fixture.main, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  644. })
  645. it('never masks an inherited custom pairing merge driver', async () => {
  646. const fixture = createFixture()
  647. git(fixture, fixture.main, [
  648. 'config', '--local', 'merge.dsh-translation-pairing.driver', 'inherited-driver %A',
  649. ])
  650. const result = await runInstaller(fixture, fixture.main)
  651. expect(result.status).toBe(1)
  652. expect(result.stderr).toContain('refusing to mask inherited merge.dsh-translation-pairing.driver')
  653. expect(git(fixture, fixture.main, [
  654. 'config', '--local', '--get', 'merge.dsh-translation-pairing.driver',
  655. ])).toBe('inherited-driver %A')
  656. expect(gitResult(fixture, fixture.main, [
  657. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.driver',
  658. ]).status).toBe(1)
  659. expect(gitResult(fixture, fixture.main, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  660. })
  661. it('does not pass unrelated command-scoped Git config to Lefthook', async () => {
  662. const fixture = createFixture()
  663. const result = await runInstaller(fixture, fixture.main, {
  664. DSH_TEST_FORBIDDEN_GIT_CONFIG_KEY: 'dsh.testSentinel',
  665. GIT_CONFIG_COUNT: '1',
  666. GIT_CONFIG_KEY_0: 'dsh.testSentinel',
  667. GIT_CONFIG_VALUE_0: 'must-not-reach-lefthook',
  668. })
  669. expect(result.status, result.stderr).toBe(0)
  670. expect(existsSync(join(hooksPath(fixture, fixture.main), 'pre-commit'))).toBe(true)
  671. })
  672. it('never overrides a hook path included by worktree config', async () => {
  673. const fixture = createFixture()
  674. const commonConfig = join(commonDirectory(fixture), 'config')
  675. const worktreeConfig = join(gitDirectory(fixture, fixture.main), 'config.worktree')
  676. const includedConfig = join(fixture.container, 'included-worktree.gitconfig')
  677. const includedHooks = join(fixture.container, 'included-hooks')
  678. const sentinel = join(includedHooks, 'pre-commit')
  679. write(sentinel, '#!/bin/sh\n# included-worktree sentinel\n', 0o755)
  680. git(fixture, fixture.main, ['config', '--file', includedConfig, 'core.hooksPath', includedHooks])
  681. git(fixture, fixture.main, ['config', '--file', commonConfig, 'core.repositoryFormatVersion', '1'])
  682. git(fixture, fixture.main, ['config', '--file', commonConfig, 'extensions.worktreeConfig', 'true'])
  683. git(fixture, fixture.main, ['config', '--file', worktreeConfig, 'include.path', includedConfig])
  684. const result = await runInstaller(fixture, fixture.main, {
  685. DSH_LEFTHOOK_ALLOW_HOOKS_PATH_OVERRIDE: '1',
  686. })
  687. expect(result.status).toBe(1)
  688. expect(result.stderr).toContain('worktree-scoped core.hooksPath')
  689. expect(git(fixture, fixture.main, ['config', '--get', 'core.hooksPath'])).toBe(includedHooks)
  690. expect(readFileSync(sentinel, 'utf8')).toBe('#!/bin/sh\n# included-worktree sentinel\n')
  691. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  692. })
  693. it('restores the previous hook lookup when Lefthook installation fails', async () => {
  694. const fixture = createFixture()
  695. const common = commonDirectory(fixture)
  696. const legacyHook = join(common, 'hooks/pre-push')
  697. write(legacyHook, '#!/bin/sh\n# legacy pre-push\n', 0o755)
  698. const result = await runInstaller(fixture, fixture.main, { DSH_TEST_LEFTHOOK_FAIL: '1' })
  699. expect(result.status).toBe(1)
  700. expect(result.stderr).toContain('exit status 77')
  701. expect(gitResult(fixture, fixture.main, ['config', '--worktree', '--get', 'core.hooksPath']).status).toBe(1)
  702. expect(gitResult(fixture, fixture.main, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  703. expect(gitResult(fixture, fixture.main, [
  704. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.name',
  705. ]).status).toBe(1)
  706. expect(gitResult(fixture, fixture.main, [
  707. 'config', '--worktree', '--get', 'merge.dsh-translation-pairing.driver',
  708. ]).status).toBe(1)
  709. expect(readFileSync(legacyHook, 'utf8')).toBe('#!/bin/sh\n# legacy pre-push\n')
  710. })
  711. it('does not publish worktree integration when the pairing driver probe fails', async () => {
  712. const fixture = createFixture()
  713. rmSync(join(fixture.main, 'node_modules/tsx'), { recursive: true, force: true })
  714. const result = await runInstaller(fixture, fixture.main)
  715. expect(result.status).toBe(1)
  716. expect(result.stderr).toContain('merge-translation-pairing.ts --probe failed')
  717. expect(gitResult(fixture, fixture.main, ['config', '--get', 'core.hooksPath']).status).toBe(1)
  718. expect(gitResult(fixture, fixture.main, [
  719. 'config', '--get', 'merge.dsh-translation-pairing.driver',
  720. ]).status).toBe(1)
  721. })
  722. it('reports installation and hook-path rollback failures together', async () => {
  723. const fixture = createFixture()
  724. const result = await runInstaller(fixture, fixture.main, {
  725. DSH_TEST_LEFTHOOK_BREAK_WORKTREE_CONFIG: '1',
  726. DSH_TEST_LEFTHOOK_FAIL: '1',
  727. })
  728. expect(result.status).toBe(1)
  729. expect(result.stderr).toContain('Lefthook installation failed')
  730. expect(result.stderr).toContain('exit status 77')
  731. expect(result.stderr).toContain('worktree integration rollback also failed')
  732. expect(result.stderr).toContain('git config --worktree --unset-all core.hooksPath failed')
  733. expect(result.stderr).toContain('git config --worktree --unset-all merge.dsh-translation-pairing.driver failed')
  734. })
  735. it('refuses an unowned directory at the reserved worktree hook path', async () => {
  736. const fixture = createFixture()
  737. const reservedHook = join(hooksPath(fixture, fixture.main), 'pre-commit')
  738. write(reservedHook, '#!/bin/sh\n# user content\n', 0o755)
  739. const result = await runInstaller(fixture, fixture.main)
  740. expect(result.status).toBe(1)
  741. expect(result.stderr).toContain('refusing to overwrite unowned hooks directory')
  742. expect(readFileSync(reservedHook, 'utf8')).toBe('#!/bin/sh\n# user content\n')
  743. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  744. })
  745. it.skipIf(process.platform === 'win32')('rejects Git without config-scope support before mutation', async () => {
  746. const fixture = createFixture()
  747. const realGit = commandResult('which', ['git'], fixture.main, fixture.env).stdout.trim()
  748. const fakeBin = join(fixture.container, 'fake-bin')
  749. const fakeGit = join(fakeBin, 'git')
  750. write(
  751. fakeGit,
  752. `#!/bin/sh\nif [ "$1" = "--version" ]; then echo "git version 2.25.0"; exit 0; fi\nexec "${realGit}" "$@"\n`,
  753. 0o755,
  754. )
  755. const result = await runInstaller(fixture, fixture.main, {
  756. PATH: `${fakeBin}:${fixture.env.PATH ?? ''}`,
  757. })
  758. expect(result.status).toBe(1)
  759. expect(result.stderr).toContain('Git 2.26 or newer is required')
  760. expect(gitResult(fixture, fixture.main, ['config', '--get', 'extensions.worktreeConfig']).status).toBe(1)
  761. expect(existsSync(hooksPath(fixture, fixture.main))).toBe(false)
  762. })
  763. })