Skip to main content

Module rule_require_root

Module rule_require_root 

Source
Expand description

Pure decision of the require-root policy. What: Pure decision of the require-root policy: commands run from the repository root. Why: Running Git from a subdirectory makes pathspecs mean something else. The policy rejects that, except for commands that need no repository. This file decides from the argument list alone which commands are exempt, and from two paths the caller measured whether the directory is the root. It reads no file and starts no process.

In TS you’d write (pseudocode):

// decideRequireRoot(args): 'exempt' | 'needs-root'
// resolveRequireRoot({ effectiveDirectory, repositoryRoot }): 'pass' | Violation

Structs§

RequireRootFacts
What: The two measurements the decision needs. Option<PathBuf> is “a path or nothing”. Why: Finding them needs the filesystem and Git’s -C handling, which stay outside this file. repository_root is nothing when the directory is in no repository.
RequireRootViolation
What: A require-root rejection with its user-facing text. String is owned text. Why: The text names both directories and both ways forward.

Enums§

RequireRootDecision
What: The outcome of looking at the argument list only. Why: Most commands need a measurement the caller makes; exempt ones never do.
RequireRootExemption
What: Why a command is exempt. An enum is a closed set of named alternatives. Why: The caller logs the reason; the decision itself is the same for all three.
RequireRootVerdict
What: The outcome once the two paths are known. Why: Either the command is forwarded unchanged or it is rejected with a message.

Constants§

NOT_AT_ROOT_CODE
What: The finding code of a require-root rejection. &str is borrowed text baked into the program. Why: Callers and transcripts identify the finding by this stable code.

Functions§

decide_require_root
What: Decide from the argument list whether the command is exempt. wrapper_flags are the caller’s wrapper-only spellings, which Git must not see as unknown options. Why: An exempt command is forwarded without touching the filesystem.
resolve_require_root
What: Decide from the measured paths whether to forward or reject. &RequireRootFacts borrows the measurements read-only. Why: Outside a repository Git reports its own error if the subcommand needs one. Gotcha: Paths compare by components, so /repo/ and /repo are the same directory; symbolic links are the caller’s concern.