Skip to main content

checkout_at

Function checkout_at 

Source
pub fn checkout_at(dir: &Path) -> Option<Checkout>
Expand description

Which kind of checkout is rooted at dir, or None if there is not one.

Asked of git rather than read out of the .git file, for this module’s founding reason: the file’s gitdir: line has to be resolved relative to the work tree, can be absolute or relative, and points somewhere whose shape is what distinguishes a linked work tree from a submodule. A hand-rolled reader gets that wrong quietly, and quietly is the failure mode a cleaner cannot afford — here it would mean reading a submodule as disposable.

The discriminator is git’s own: --git-dir and --git-common-dir are equal for a repository and for a submodule, and a linked work tree is the only case where the first sits at <common>/worktrees/<name>. Measured against all three, rather than inferred from the documentation.

Fails toward Repository — never toward Linked — whenever git cannot be run or will not answer. Everything downstream reads Linked as permission.