970043bd8a
A fresh `git init` in detachGitDir dropped core.sparseCheckout and the sparse-checkout patterns, and rebuilding the index via write-tree/ read-tree discarded skip-worktree bits. Files intentionally absent from a sparse working tree then read as deletions, which delta capture could apply back to the parent. detachGitDir now restores the index verbatim (preserving skip-worktree, assume-unchanged, and exact stage entries) and carries core.sparseCheckout, core.sparseCheckoutCone, and info/sparse-checkout into the detached .git before restoring the index. Falls back to read-tree HEAD only when the source had no index. Fixes #6003