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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225/** Commit options a replay repeats outside native `git commit`: whether hooks were bypassed with `--no-verify`, and the key a signed commit is re-signed with.
@module */import { PATHSPEC_SEPARATOR, } from '../escape-hatch.ts';import { normaliseCommitArgs, } from '../parser/commit-normalise.ts';
/** Short commit options that consume the next token. */const VALUE_LETTERS: ReadonlySet<string> = new Set([ 'm', 'F', 'C', 'c', 't',]);
/** Short commit options whose value, when present, is attached (`-S<key>`, `-u<mode>`). */const ATTACHED_VALUE_LETTERS: ReadonlySet<string> = new Set([ 'S', 'u',]);
/** Long commit options that consume the next token when written without `=`. */const LONG_VALUE_OPTIONS: ReadonlySet<string> = new Set([ '--message', '--file', '--reuse-message', '--reedit-message', '--squash', '--fixup', '--author', '--date', '--cleanup', '--trailer', '--template', '--pathspec-from-file',]);
/** Replay-relevant commit options. */export type ReplayOptions = Readonly<{ /** Whether `pre-commit` and `commit-msg` were bypassed. */ noVerify: boolean; /** Key ID given to `-S` or `--gpg-sign`, absent for the configured key. */ signingKey?: string;}>;
/** Option state while scanning. */type ScanState = Readonly<{ /** Latest `--verify` or `--no-verify` decision. */ noVerify: boolean; /** Latest signing key, empty for the configured key. */ signingKey: string; /** Whether the next token is an option value. */ valueNext: boolean; /** Whether the pathspec separator was passed. */ done: boolean;}>;
/** Applies one short-option cluster.
@param state - state before the cluster
@param token - cluster such as `-nS` or `-Skey`
@returns state after the cluster */function scanCluster({ state, token,}: Readonly<{ state: ScanState; token: string;}>,): ScanState { /** Letters after the dash. */ const letters = Array.from(token.slice(1,),); /** First letter whose value follows, attached or separated. */ const valueIndex = letters.findIndex(function takesValue(letter,): boolean { return VALUE_LETTERS.has(letter,) || ATTACHED_VALUE_LETTERS.has(letter,); },); /** Boolean flags before any value letter. */ const flags = valueIndex === (-1) ? letters : letters.slice( 0, valueIndex, ); /** Value letter, when present. */ const valueLetter = valueIndex === (-1) ? '' : letters[valueIndex] ?? ''; /** Attached value after the value letter. */ const attached = valueIndex === (-1) ? '' : letters.slice(valueIndex + 1,) .join('',); return { ...state, noVerify: state.noVerify || flags.includes('n',), signingKey: valueLetter === 'S' ? attached : state.signingKey, valueNext: VALUE_LETTERS.has(valueLetter,) && (attached === ''), };}
/** Applies one token.
@param state - state before the token
@param token - argument
@returns state after the token */function scanToken({ state, token,}: Readonly<{ state: ScanState; token: string;}>,): ScanState { if (state.done) return state; if (state.valueNext) return { ...state, valueNext: false, }; if (token === PATHSPEC_SEPARATOR) return { ...state, done: true, }; if ((token === '--no-verify') || (token === '--verify')) return { ...state, noVerify: token === '--no-verify', }; if ((token === '--gpg-sign') || token.startsWith('--gpg-sign=',)) return { ...state, signingKey: token.slice('--gpg-sign='.length,), }; if (LONG_VALUE_OPTIONS.has(token,)) return { ...state, valueNext: true, }; if (token.startsWith('-',) && (!token.startsWith('--',)) && (token.length > 1)) return scanCluster({ state, token, },); return state;}
/** Reads the replay-relevant options from private commit arguments.
@param commitArgs - post-`commit` arguments native preparation ran with
@returns options
@example ```ts replayOptions(['-n', '-Sabc', '-m', 'x']); // { noVerify: true, signingKey: 'abc' } ``` */export function replayOptions(commitArgs: readonly string[],): ReplayOptions { /** Final scan state. */ const state = normaliseCommitArgs(commitArgs,) .reduce( function applyToken( current: ScanState, token, ): ScanState { return scanToken({ state: current, token, },); }, { noVerify: false, signingKey: '', valueNext: false, done: false, }, ); return { noVerify: state.noVerify, ...(state.signingKey === '' ? {} : { signingKey: state.signingKey, }), };}