Skip to main content

head_on_branch

Function head_on_branch 

Source
pub fn head_on_branch(dir: &Path) -> bool
Expand description

Whether HEAD names a branch rather than sitting detached.

The one way removing a linked work tree can lose a commit. A commit made on a detached HEAD is reachable only through that work tree’s own HEAD, so once the directory is gone and the administrative files are pruned nothing refers to it and gc will collect it — measured, not reasoned about: git fsck --unreachable lists it immediately after. A commit on a branch is reachable through an ordinary ref in the repository and survives.

Errs toward “detached” on every failure, which is the answer that keeps the directory.