Skip to main content

Module move_head

Module move_head 

Source
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 symbolhere
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_FORCEMoveHeadFlags::force
is_submodule_activeMoveHeadContext::active
is_submodule_populated_gentlyMoveHeadContext::populated
submodule_has_dirty_indexMoveHeadContext::has_dirty_index

Structs§

MoveHeadContext
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).
MoveHeadFlags
Flags controlling a move-head check, porting SUBMODULE_MOVE_HEAD_*.

Enums§

MoveHeadVerdict
The verdict of a move-head check, porting the return contract of submodule_move_head in DRY_RUN mode as consumed by check_submodule_move_head.

Functions§

check_move_head
Port of submodule_move_head (git submodule.c) restricted to the dry-run verification path that check_submodule_move_head uses — the actual hook a tree-switch engine calls.
check_submodule_move_head
Port of check_submodule_move_head (git unpack-trees.c). Thin wrapper that always runs in dry-run mode and translates o->reset into the FORCE flag.
verify_clean_submodule
Port of verify_clean_submodule (git unpack-trees.c). Checks that checking out ce’s oid in the submodule subdir won’t overwrite working files, given the submodule’s current head (old_sha1, None when HEAD is unresolved).