install-lefthook.spec.ts 40 KB

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