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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208/** Private commit-index initialization and intended tree. @module */import type { GitObjectId, } from '../api/policy-types.ts';import { runTransactionGit, } from './commit-transaction-git.ts';import { copyIndexFile, } from './index-file-timestamps.ts';import type { CommitTransactionWorkspace, } from './commit-transaction-workspace.ts';
/** Strict Git object decoder. */const DECODER = new TextDecoder( 'utf-8', { fatal: true, },);
/** Builds Git-native path selection arguments. @param pathspecs - direct pathspec tokens @param pathspecFile - optional file source @param pathspecFileNul - whether source uses NUL delimiters @returns exact git add selection arguments */function selectionArguments({ pathspecs, pathspecFile, pathspecFileNul,}: Readonly<{ pathspecs: readonly string[]; pathspecFile?: string; pathspecFileNul: boolean;}>,): readonly string[] { return pathspecFile === undefined ? [ '--', ...pathspecs, ] : [ `--pathspec-from-file=${pathspecFile}`, ...(pathspecFileNul ? ['--pathspec-file-nul',] : []), ];}
/** Copies or builds private commit index and snapshots original index. @param workspace - owned transaction workspace @param gitPath - resolved Git executable @param cwd - effective repository directory @param mode - commit selection semantics @param pathspecs - engine-selected explicit paths @param pathspecFile - optional pathspec source file @param pathspecFileNul - whether source uses NUL delimiters @param stageIntoIndex - whether copied index receives selected worktree state @param stageTrackedChanges - whether copied index receives every tracked modification and deletion, as `commit -a` does @param baseRevision - recorded base commit, or the empty tree for an unborn base @param objectDirectory - store receiving the blobs staging writes, the transaction's shadow store so a real `gc` cannot prune them @example ```ts await initializeCommitIndex({ workspace, gitPath: '/usr/bin/git', cwd: '/repo', mode: 'index', pathspecs: [], pathspecFileNul: false, baseRevision }); ``` */export async function initializeCommitIndex({ workspace, gitPath, cwd, mode, pathspecs, pathspecFile, pathspecFileNul, stageIntoIndex = false, stageTrackedChanges = false, baseRevision, objectDirectory,}: Readonly<{ workspace: Pick<CommitTransactionWorkspace, 'realIndexPath' | 'capturedIndexPath' | 'commitIndexPath'>; gitPath: string; cwd: string; mode: 'explicit-path' | 'index'; pathspecs: readonly string[]; pathspecFile?: string; pathspecFileNul: boolean; stageIntoIndex?: boolean; stageTrackedChanges?: boolean; baseRevision: string; objectDirectory: string;}>,): Promise<void> { await copyIndexFile({ sourcePath: workspace.realIndexPath, destinationPath: workspace.capturedIndexPath, },); if (mode === 'index') { await copyIndexFile({ sourcePath: workspace.capturedIndexPath, destinationPath: workspace.commitIndexPath, },); if (stageTrackedChanges) // Whole-tree update of tracked paths, exactly what `commit -a` stages, captured once at invocation. await runTransactionGit({ gitPath, cwd, indexPath: workspace.commitIndexPath, args: [ 'add', '--update', '--', ':/', ], objectDirectory, },); if (!stageIntoIndex) return; } else // The recorded base, never live `HEAD`: another landing may have moved it since invocation. await runTransactionGit({ gitPath, cwd, indexPath: workspace.commitIndexPath, args: [ 'read-tree', baseRevision, ], objectDirectory, },); await runTransactionGit({ gitPath, cwd, indexPath: workspace.commitIndexPath, args: [ 'add', '--all', ...selectionArguments({ pathspecs, ...(pathspecFile === undefined ? {} : { pathspecFile, }), pathspecFileNul, },), ], objectDirectory, },);}
/** Writes exact intended tree from private commit index. @param workspace - transaction workspace @param gitPath - resolved Git executable @param cwd - repository directory @param indexPath - index to write; the workspace's private commit index when absent @returns intended Git tree OID @example ```ts await writePrivateTree({ workspace, gitPath: '/usr/bin/git', cwd: '/repo' }); ``` */export async function writePrivateTree({ workspace, gitPath, cwd, indexPath = workspace.commitIndexPath,}: Readonly<{ workspace: Pick<CommitTransactionWorkspace, 'commitIndexPath' | 'objectDirectory'>; gitPath: string; cwd: string; indexPath?: string;}>,): Promise<GitObjectId> { /** Git tree object written from private index into the shadow store. */ const output = await runTransactionGit({ gitPath, cwd, indexPath, args: ['write-tree',], objectDirectory: workspace.objectDirectory, },); /** Exact intended tree OID. */ const oid = DECODER.decode(output.stdout,) .trim(); if (oid.length === 0) throw new TypeError('Git returned empty private tree identity.',); return oid;}