Expand description
Submodule move-head / verify-clean primitives — a Rust port of the
verification half of git’s submodule.c::submodule_move_head plus the
unpack-trees.c wrappers check_submodule_move_head and
verify_clean_submodule.
These are exactly the hooks a tree-switch engine (checkout / reset /
read-tree, i.e. unpack-trees) needs to answer “would moving this
submodule’s HEAD from old to new lose uncommitted work?” before
touching the worktree. They are written as pure decision logic over a
caller-supplied MoveHeadContext: the crate owns the algorithm (the
active/populated gating and the dirty-index → reject rule); the caller owns
the I/O (resolving the submodule gitdir, reading its index, checking
dirtiness). That split keeps this crate dependency-light and lets both the
submodule CLI command and the tree-switch commands drive the SAME logic.
§Mapping to git
| git symbol | here |
|---|---|
submodule_move_head(..., DRY_RUN) | check_move_head |
check_submodule_move_head (unpack-trees.c) | check_move_head |
verify_clean_submodule (unpack-trees.c) | verify_clean_submodule |
SUBMODULE_MOVE_HEAD_FORCE | MoveHeadFlags::force |
is_submodule_active | MoveHeadContext::active |
is_submodule_populated_gently | MoveHeadContext::populated |
submodule_has_dirty_index | MoveHeadContext::has_dirty_index |
Structs§
- Move
Head Context - Everything the move-head decision needs about one submodule at one path.
The caller resolves these via whatever I/O it already has (the CLI reads the
submodule’s
.git+ index; the unpack-trees engine reads the in-memory index entry + on-disk submodule). - Move
Head Flags - Flags controlling a move-head check, porting
SUBMODULE_MOVE_HEAD_*.
Enums§
- Move
Head Verdict - The verdict of a move-head check, porting the return contract of
submodule_move_headin DRY_RUN mode as consumed bycheck_submodule_move_head.
Functions§
- check_
move_ head - Port of
submodule_move_head(gitsubmodule.c) restricted to the dry-run verification path thatcheck_submodule_move_headuses — the actual hook a tree-switch engine calls. - check_
submodule_ move_ head - Port of
check_submodule_move_head(gitunpack-trees.c). Thin wrapper that always runs in dry-run mode and translateso->resetinto the FORCE flag. - verify_
clean_ submodule - Port of
verify_clean_submodule(gitunpack-trees.c). Checks that checking outce’s oid in the submodule subdir won’t overwrite working files, given the submodule’s current head (old_sha1,Nonewhen HEAD is unresolved).