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' | ViolationStructs§
- Require
Root Facts - What:
The two measurements the decision needs.
Option<PathBuf>is “a path or nothing”. Why: Finding them needs the filesystem and Git’s-Chandling, which stay outside this file.repository_rootis nothing when the directory is in no repository. - Require
Root Violation - What:
A require-root rejection with its user-facing text.
Stringis owned text. Why: The text names both directories and both ways forward.
Enums§
- Require
Root Decision - What: The outcome of looking at the argument list only. Why: Most commands need a measurement the caller makes; exempt ones never do.
- Require
Root Exemption - What:
Why a command is exempt.
An
enumis a closed set of named alternatives. Why: The caller logs the reason; the decision itself is the same for all three. - Require
Root Verdict - 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.
&stris 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_flagsare 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.
&RequireRootFactsborrows 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/repoare the same directory; symbolic links are the caller’s concern.