MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/restore.rs:448–638  ·  view source on GitHub ↗

Execute the restore command. # Process 1. Find and open the repository 2. Guard a whole-tree restore behind `--force` 3. Determine files to restore 4. If `--dry-run`, preview changes 5. Otherwise, restore files to pristine state

(&self)

Source from the content-addressed store, hash-verified

446 /// 4. If `--dry-run`, preview changes
447 /// 5. Otherwise, restore files to pristine state
448 fn run(&self) -> CliResult<()> {
449 // Route every form through the daemon when reachable — the
450 // non-dry-run forms over Restore; the dry-run previews over
451 // PreviewRestore (the listing form, and the single-file
452 // pristine-bytes dump through the content arm). The single-file
453 // shape check stats the working copy only — never a redb open.
454 if crate::commands::rpc::restore(self)? {
455 return Ok(());
456 }
457 if self.dry_run {
458 // The single-file dump applies only when the argument is
459 // exactly one concrete file (the local body's rule: a
460 // directory or trailing-slash filter has no pristine bytes
461 // of its own and previews as a listing).
462 let single_file_arg = self.files.len() == 1
463 && !self.files[0].ends_with('/')
464 && find_repository_root()
465 .map(|root| !root.join(&self.files[0]).is_dir())
466 .unwrap_or(true);
467 if single_file_arg && crate::commands::rpc::restore_single_dry_run(&self.files[0])? {
468 return Ok(());
469 }
470 if crate::commands::rpc::restore_preview(self.files.clone())? {
471 return Ok(());
472 }
473 }
474
475 // The NOT-A-REPOSITORY FALLBACK (and the unreachable-daemon
476 // fallback): the root lookup below reports the same refusal
477 // without opening redb when no repository surrounds the cwd.
478 // Find repository
479 let repo_root = find_repository_root()?;
480 let mode = if self.dry_run {
481 WorkspaceTxnMode::Observe
482 } else {
483 WorkspaceTxnMode::Reconcile
484 };
485 let mut repo = match mode {
486 WorkspaceTxnMode::Observe => Repository::open_readonly(&repo_root),
487 WorkspaceTxnMode::Reconcile => Repository::open_for_workspace_transaction(&repo_root),
488 WorkspaceTxnMode::Force => unreachable!("restore never forces workspace entry"),
489 }
490 .map_err(CliError::Repository)?;
491 if !self.dry_run {
492 repo.hydrate_remote_sandbox()
493 .map_err(CliError::Repository)?;
494 }
495 let workspace = enter_workspace(&mut repo, mode)?;
496 let working_copy = workspace.working_copy();
497 let workspace_view = workspace.view().name.clone();
498
499 // Compute status once. Restore only touches tracked files, so we skip
500 // the untracked scan, and we reuse this single status for both the
501 // safety guard and the file list (no second tree walk).
502 let status = repo
503 .status(working_copy, Self::status_options())
504 .map_err(CliError::Repository)?;
505

Callers

nothing calls this directly

Calls 15

restoreFunction · 0.85
find_repository_rootFunction · 0.85
restore_single_dry_runFunction · 0.85
restore_previewFunction · 0.85
print_hintFunction · 0.85
print_warningFunction · 0.85
print_successFunction · 0.85
is_dirMethod · 0.80
requires_forceMethod · 0.80
files_to_restoreMethod · 0.80
dry_run_single_fileMethod · 0.80

Tested by

no test coverage detected