Skip to main content

Module rule_commit_only

Module rule_commit_only 

Source
Expand description

Pure decision of the commit-only transform. What: The pure decision of the commit-only transform: insert -o after git commit, or say why not. Why: Every commit must name the paths it includes. Two decisions need a repository fact (sequencer state, index against HEAD); this module asks for the fact by returning a Needs... variant and the caller answers through a resolve_... function, so no process or file is touched here.

In TS you’d write (pseudocode):

// const rule = makeCommitOnly({ checkIndexDiffersFromHead, checkSequencerInProgress });

Structs§

CommitOnlyViolation
What: One expected rejection. String is owned UTF-8 text (sibling &str borrows). Why: The message is built per invocation, so the violation owns it.
PendingInjection
What: What resolve_index_state needs to finish the decision. Why: The first call already located commit and the pathless-allowed flags.

Enums§

CommitOnlyDecision
What: The transform’s answer, or the repository fact it needs first. Why: The facts are fetched lazily: most commands are decided from arguments alone.
CommitOnlyViolationCode
What: Stable rejection codes. An enum is a closed set of named alternatives. Why: Events carry commit-only/<code>; consumers match the code, not the message.

Functions§

decide_commit_only
What: Decide from arguments alone, or name the repository fact needed. Result<A, B> is “either success A or failure B”. Why: The order mirrors the TypeScript rule: escape hatch, opt-out, -a, pathspec source, explicit only, modes Git owns, then the dirty-index guard. Gotcha: Err means Git 2.56.0 itself refuses the commit options; the caller forwards such a command unchanged so Git prints its own error.
resolve_index_state
What: Finish a NeedsIndexState decision. &PendingInjection borrows the pending data. Why: An injected --only on a pathless amend or empty commit reuses HEAD’s tree, so a dirty index would be ignored silently; an equal or unknown index is safe to inject.
resolve_sequencer_state
What: Finish a NeedsSequencerState decision. Why: A pathless commit concludes a merge, cherry-pick or revert; otherwise it is refused.
violation_code_text
What: The kebab-case spelling of a code. &'static str is text baked into the program. Why: The event format predates this module and its spellings must not drift.