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

Method run

atomic-cli/src/commands/unrecord.rs:86–152  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

84
85impl Command for Unrecord {
86 fn run(&self) -> CliResult<()> {
87 // Route through the daemon when reachable (non-dry-run); the local
88 // path below is unchanged.
89 if crate::commands::rpc::unrecord(self)? {
90 return Ok(());
91 }
92 // The dry-run form is a read — PreviewMutation (UnrecordPreview).
93 if self.dry_run && crate::commands::rpc::unrecord_preview(self.change.clone())? {
94 return Ok(());
95 }
96
97 let repo_root = find_repository_root()?;
98 let mode = if self.dry_run {
99 WorkspaceTxnMode::Observe
100 } else {
101 WorkspaceTxnMode::Reconcile
102 };
103 let mut repo = match mode {
104 WorkspaceTxnMode::Observe => Repository::open_readonly(&repo_root),
105 WorkspaceTxnMode::Reconcile => Repository::open_for_workspace_transaction(&repo_root),
106 WorkspaceTxnMode::Force => unreachable!("unrecord never forces workspace entry"),
107 }
108 .map_err(|e| match e {
109 atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound {
110 searched_path: path.into(),
111 },
112 other => CliError::Repository(other),
113 })?;
114
115 let workspace = enter_workspace(&mut repo, mode)?;
116 let options = if self.dry_run {
117 UnrecordOptions::dry_run()
118 } else {
119 UnrecordOptions::new()
120 }
121 .view(workspace.view().name.clone());
122
123 let outcome = if let Some(ref prefix) = self.change {
124 let hash = resolve_change(&repo, prefix)?;
125 repo.unrecord(&hash, options)
126 .map_err(CliError::Repository)?
127 } else {
128 // Unrecord the most recent change
129 repo.unrecord_last(options).map_err(|e| match e {
130 atomic_repository::RepositoryError::Unrecord(msg)
131 if msg.contains("empty") || msg.contains("Empty") =>
132 {
133 CliError::InvalidArgument {
134 message: "View is empty — nothing to unrecord".to_string(),
135 }
136 }
137 other => CliError::Repository(other),
138 })?
139 };
140
141 if outcome.was_dry_run {
142 for hash in &outcome.unrecorded {
143 print_warning(&format!("Would unrecord: {}", hash.to_base32()));

Callers

nothing calls this directly

Calls 13

unrecordFunction · 0.85
unrecord_previewFunction · 0.85
find_repository_rootFunction · 0.85
RepositoryClass · 0.85
resolve_changeFunction · 0.85
print_warningFunction · 0.85
print_successFunction · 0.85
unrecord_lastMethod · 0.80
enter_workspaceFunction · 0.70
cloneMethod · 0.45
viewMethod · 0.45
unrecordMethod · 0.45

Tested by

no test coverage detected