Restore a single file according to its status. - `Added` (tracked but not recorded): undo tracking. The file stays on disk and becomes untracked, so we never destroy content the user created. This is what makes `restore ` honest about the "new file" change reported by `status`. - Otherwise (`Modified` / `Deleted`): restore the file's content from the pristine state. Returns the outcome
(
&self,
repo: &Repository,
working_copy: atomic_core::WorkingCopyId,
view: &str,
_repo_root: &Path,
path: &Path,
status: FileStatus,
)
| 370 | /// |
| 371 | /// Returns the outcome so the caller can report it accurately. |
| 372 | fn restore_file( |
| 373 | &self, |
| 374 | repo: &Repository, |
| 375 | working_copy: atomic_core::WorkingCopyId, |
| 376 | view: &str, |
| 377 | _repo_root: &Path, |
| 378 | path: &Path, |
| 379 | status: FileStatus, |
| 380 | ) -> CliResult<RestoreOutcome> { |
| 381 | if status == FileStatus::Added { |
| 382 | // Undo the `add`: stop tracking, but keep the file on disk. |
| 383 | repo.remove( |
| 384 | working_copy, |
| 385 | path, |
| 386 | TrackingOptions::default().with_recursive(false), |
| 387 | ) |
| 388 | .map_err(CliError::Repository)?; |
| 389 | return Ok(RestoreOutcome::Untracked); |
| 390 | } |
| 391 | |
| 392 | // Restore content from pristine. |
| 393 | let content = repo.get_file_content_on_view(path, view).map_err(|e| { |
| 394 | CliError::Internal(anyhow::anyhow!("Failed to get file content: {}", e)) |
| 395 | })?; |
| 396 | |
| 397 | match content { |
| 398 | Some(_) => { |
| 399 | repo.materialize_paths( |
| 400 | working_copy, |
| 401 | std::collections::HashSet::from([path.to_string_lossy().into_owned()]), |
| 402 | ) |
| 403 | .map_err(CliError::Repository)?; |
| 404 | Ok(RestoreOutcome::Restored) |
| 405 | } |
| 406 | None => { |
| 407 | // No pristine content available; nothing safe to do. |
| 408 | Ok(RestoreOutcome::Skipped) |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /// Check if a path matches any of the specified file filters. |
| 414 | fn matches_filter(&self, path: &str) -> bool { |