Skip to main content

Module rule_linked_worktree

Module rule_linked_worktree 

Source
Expand description

Pure decision of the linked-worktree-only policy. What: Pure decision of the linked-worktree-only policy: commands that can discard uncommitted state never run in the main worktree, and run in a linked worktree only while it is clean. Why: git stash that changes state, a deleting git clean, a git reset that is not --soft, git restore, git checkout and git switch forms that overwrite files, a forced rm, mv, or checkout-index, read-tree --reset and an --abort can throw away work, and the loss leaves no record. This file decides from the arguments alone whether the command is guarded and when, and from the worktree kind and dirtiness the caller measured whether to reject it. It starts no process.

In TS you’d write (pseudocode):

// decideLinkedWorktree(['clean', '-fd']) => { kind: 'needs-effective-target', command: 'clean' }

Re-exports§

pub use super::rule_linked_worktree_messages::dirty_worktree_message;
pub use super::rule_linked_worktree_messages::main_worktree_message;
pub use super::rule_linked_worktree_messages::outside_worktree_message;

Enums§

GuardedCommand
What: The forms the policy guards. An enum is a closed set of named alternatives. #[derive(...)] asks the compiler to generate copying, debug printing and ==. Why: Each form has its own rejection text, because the same subcommand serves different intents: restore --staged unstages while restore <path> reverts a file.
LinkedWorktreeDecision
What: The outcome of looking at the argument list only. Why: Most commands are not guarded and need no repository query at all.

Constants§

LINKED_WORKTREE_REQUIRED_CODE
What: The finding code of a linked-worktree rejection. &str is borrowed text baked into the program. Why: Callers identify the finding by this stable code.

Functions§

decide_linked_worktree
What: Decide from the argument list. &[OsString] borrows the arguments, already free of wrapper controls. Why: A command that is not guarded, or that Git itself refuses, needs no measurement.
dirty_scope
What: The files that count as uncommitted state for a guarded command. Why: A clean deletes untracked files, so they count for it; every other form loses tracked changes only.
resolve_linked_worktree
What: Decide from the measured worktree kind: the rejection text, or nothing to let the command through for now. Why: The main worktree and a place without a worktree reject at once; a linked worktree and an allowlisted tool cache pass this step, and a linked worktree is then judged by its dirtiness.