(&self)
| 84 | |
| 85 | impl 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())); |
nothing calls this directly
no test coverage detected