Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254import { readdir, readFile, writeFile,} from 'node:fs/promises';import { join, } from 'node:path';
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { commitPaths, copySummaryLines, createTempDirectory, initializeRepository, requireSuccess, runRealGit, captureWrapper,} from './worktree-copy-fixture.unit.test.ts';
/** One worktree-add form and destination used by built wrapper catalog. */type WorktreeForm = Readonly<{ /** Human-readable form name. */ name: string; /** Complete arguments passed to built wrapper. */ args: readonly string[]; /** Created worktree destination. */ destinationRoot: string;}>;
await describe({ name: 'worktree creation form coverage', concurrency: 1, children: [ it({ name: 'copies ignored state for branch, force, existing, detached, orphan, convenience, and remote-guess forms', fn: async () => { await using fixture = await createTempDirectory(); /** Invoking source repository. */ const repositoryRoot = join(fixture.path, 'repository',); /** Local bare remote used by unique remote-guess form. */ const remoteRoot = join(fixture.path, 'remote.git',); await initializeRepository(repositoryRoot,); await writeFile(join(repositoryRoot, '.gitignore',), 'state.txt\n',); await commitPaths({ repositoryRoot, message: 'ignore worktree state', paths: ['.gitignore',], },); await writeFile(join(repositoryRoot, 'state.txt',), 'all forms\n',); await Promise.all([ runRealGit({ cwd: repositoryRoot, args: [ 'branch', 'existing-form', ], },), runRealGit({ cwd: repositoryRoot, args: [ 'branch', 'force-form', ], },), runRealGit({ cwd: fixture.path, args: [ 'init', '--bare', remoteRoot, ], },), ],); await runRealGit({ cwd: repositoryRoot, args: [ 'remote', 'add', 'origin', remoteRoot, ], },); await runRealGit({ cwd: repositoryRoot, args: [ 'push', 'origin', 'main:refs/heads/remote-guess', ], },); await runRealGit({ cwd: repositoryRoot, args: [ 'fetch', 'origin', ], },); /** Destination roots for every accepted Git 2.55 creation family. */ const destination = { branch: join(fixture.path, 'branch-form',), force: join(fixture.path, 'force-form-worktree',), existing: join(fixture.path, 'existing-form-worktree',), detached: join(fixture.path, 'detached-form',), orphan: join(fixture.path, 'orphan-form',), convenience: join(fixture.path, 'convenience-form',), remoteGuess: join(fixture.path, 'remote-guess',), } as const; /** Complete creation-form catalog. */ const forms: readonly WorktreeForm[] = [ { name: 'new branch with implicit HEAD', args: ['worktree', 'add', '-b', 'branch-form', destination.branch,], destinationRoot: destination.branch, }, { name: 'forced branch with explicit start point', args: ['worktree', 'add', '-B', 'force-form', destination.force, 'HEAD',], destinationRoot: destination.force, }, { name: 'existing branch', args: ['worktree', 'add', destination.existing, 'existing-form',], destinationRoot: destination.existing, }, { name: 'detached explicit start point', args: ['worktree', 'add', '--detach', destination.detached, 'HEAD',], destinationRoot: destination.detached, }, { name: 'orphan branch', args: ['worktree', 'add', '--orphan', '-b', 'orphan-form', destination.orphan,], destinationRoot: destination.orphan, }, { name: 'path-only convenience branch', args: ['worktree', 'add', destination.convenience,], destinationRoot: destination.convenience, }, { name: 'unique remote guess', args: ['worktree', 'add', '--guess-remote', destination.remoteGuess,], destinationRoot: destination.remoteGuess, }, ]; for (const form of forms) { // oxlint-disable-next-line no-await-in-loop -- each Git form creates repository state consumed by following assertion requireSuccess(await captureWrapper({ cwd: repositoryRoot, args: form.args, },),); // oxlint-disable-next-line no-await-in-loop -- each destination must be verified through built wrapper boundary expect(await readFile(join(form.destinationRoot, 'state.txt',), 'utf8',),) .toBe('all forms\n',); } }, },),
it({ name: 'skips synchronization under --no-worktree-copy and keeps value-position bytes', fn: async () => { await using fixture = await createTempDirectory(); /** Invoking source repository. */ const repositoryRoot = join(fixture.path, 'repository',); await initializeRepository(repositoryRoot,); await writeFile(join(repositoryRoot, '.gitignore',), 'state.txt\n',); await commitPaths({ repositoryRoot, message: 'ignore worktree state', paths: ['.gitignore',], },); await writeFile(join(repositoryRoot, 'state.txt',), 'opt out\n',); /** Destination created with synchronization opted out. */ const optedOutRoot = join(fixture.path, 'opted-out',); /** Built-wrapper creation with the wrapper-only opt-out in flag position. */ const optedOut = requireSuccess(await captureWrapper({ cwd: repositoryRoot, args: [ 'worktree', 'add', '--no-worktree-copy', '-b', 'opted-out', optedOutRoot, ], },),); expect(await readFile(join(optedOutRoot, '.gitignore',), 'utf8',),).toBe('state.txt\n',); expect(await readdir(optedOutRoot,),).not.toContain('state.txt',); expect(copySummaryLines(optedOut.stderr,),).toHaveLength(0,); /** Destination whose lock reason carries the opt-out bytes in value position. */ const valuePositionRoot = join(fixture.path, 'value-position',); /** Built-wrapper creation where the opt-out bytes sit in a value position. */ const valuePosition = requireSuccess(await captureWrapper({ cwd: repositoryRoot, args: [ 'worktree', 'add', '--lock', '--reason', '--no-worktree-copy', '-b', 'value-position', valuePositionRoot, ], },),); expect(await readFile(join(valuePositionRoot, 'state.txt',), 'utf8',),).toBe('opt out\n',); expect(copySummaryLines(valuePosition.stderr,),).toHaveLength(1,); /** Porcelain listing proving the lock reason retained the opt-out bytes. */ const listing = await runRealGit({ cwd: repositoryRoot, args: [ 'worktree', 'list', '--porcelain', ], },); expect(listing.stdout,).toContain('locked --no-worktree-copy',); }, },), ],},);