restore_entries

Function restore_entries 

Source
pub(crate) fn restore_entries(
    entries: &[&GitStatusEntry],
    branch: Option<&str>,
) -> Result<()>
Expand description

Delete newly created paths then restore modified paths (optionally from a branch)

Performs a two‑phase operation over the provided entries:

  1. Physically removes any paths that are newly added (worktree and/or index). For paths that were staged as new, their repo‑relative paths are collected and subsequently unstaged via [ytil_git::unstage], ensuring only the index is touched (no accidental content resurrection).
  2. Invokes [ytil_git::restore] for any remaining changed (non‑new) entries, optionally specifying branch so contents are restored from that branch rather than the index / HEAD.

Early exit: if after deleting new entries there are no remaining changed entries, the restore phase is skipped.

§Errors

  • Removing a file or directory for a new entry fails (I/O error from std::fs).
  • Unstaging staged new entries via [ytil_git::unstage] fails.
  • Building or executing the underlying git restore command via [ytil_git::restore] fails.

§Rationale

Using the porcelain git restore preserves nuanced semantics (e.g. respect for sparse checkout, renames) without re‑implementing them atop libgit2.

§Future Work

  • Detect & report partial failures (continue deletion on best‑effort then aggregate errors).
  • Parallelize deletions if ever shown to be a bottleneck (likely unnecessary for typical counts).