Discard a candidate staging by restoring the git index from HEAD's tree, leaving git byte-identical to its pre-operation state (the working copy is never touched). Best-effort.
(git_repo: &GitRepository)
| 401 | /// leaving git byte-identical to its pre-operation state (the working copy is |
| 402 | /// never touched). Best-effort. |
| 403 | fn restore_index_from_head(git_repo: &GitRepository) { |
| 404 | if let Ok(tree) = git_repo |
| 405 | .head() |
| 406 | .and_then(|h| h.peel_to_commit()) |
| 407 | .and_then(|c| c.tree()) |
| 408 | { |
| 409 | if let Ok(mut index) = git_repo.index() { |
| 410 | let _ = index.read_tree(&tree); |
| 411 | let _ = index.write(); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | #[cfg(test)] |
| 417 | mod tests { |
no test coverage detected