Skip to main content

Module worktree_identity

Module worktree_identity 

Source
Expand description

Repository and worktree identity as reported by real Git. What: Ask real Git which repository and worktree an invocation selects. Why: Configuration lives at the worktree top level, and worktree policies need to know main versus linked. Git applies -C, --git-dir, --work-tree and its environment itself, so the wrapper never re-implements that selection.

In TS you’d write (pseudocode):

// const identity = await resolveGitWorktreeIdentity({ args, gitPath });

Enums§

WorktreeIdentity
What: The repository shape an invocation selects. #[derive(...)] generates cloning, debug printing and ==. Why: Each shape needs different handling: no repository means no configuration, a bare repository has no worktree, and main versus linked decides worktree policies. All paths are Git’s own canonical absolute paths.

Constants§

IDENTITY_QUERY
What: The rev-parse options of the identity query, in output order. &[&str] is a borrowed list of borrowed strings compiled into the program. Why: One query answers everything. --show-toplevel is last because Git stops there in a bare repository after already printing the first three lines.

Functions§

parse_identity_output
What: Interpret the identity query’s exit state and output. std::io::Result<T> is Result<T, std::io::Error>. Why: Success prints four lines. Failure after three lines is a repository without a worktree (bare when the first line says so). Failure with no output is “not a repository”. Any other shape is rejected rather than guessed.
resolve_worktree_identity
What: Resolve the identity selected by the caller’s global Git options. &[OsString] borrows the arguments before the subcommand, unchanged. Why: Replaying the complete global prefix lets Git apply -C chains through symbolic links, --git-dir, --work-tree and environment selection exactly as it will for the forwarded command.
worktree_root
What: The worktree top level of an identity, when it has one. Option<&Path> is “a borrowed path or nothing”. Why: Configuration is loaded only for main and linked worktrees.