(&self)
| 82 | |
| 83 | impl Command for Unrecord { |
| 84 | fn run(&self) -> CliResult<()> { |
| 85 | let repo_root = find_repository_root()?; |
| 86 | let repo = Repository::open(&repo_root).map_err(|e| match e { |
| 87 | atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound { |
| 88 | searched_path: path.into(), |
| 89 | }, |
| 90 | other => CliError::Repository(other), |
| 91 | })?; |
| 92 | |
| 93 | let options = if self.dry_run { |
| 94 | UnrecordOptions::dry_run() |
| 95 | } else { |
| 96 | UnrecordOptions::new() |
| 97 | }; |
| 98 | |
| 99 | let outcome = if let Some(ref _prefix) = self.change { |
| 100 | // TODO: support unrecording a specific change by hash prefix |
| 101 | // once hash_from_prefix is available on the transaction trait. |
| 102 | return Err(CliError::InvalidArgument { |
| 103 | message: "Unrecording a specific change by hash is not yet supported. \ |
| 104 | Use `atomic unrecord` (no argument) to unrecord the last change." |
| 105 | .to_string(), |
| 106 | }); |
| 107 | } else { |
| 108 | // Unrecord the most recent change |
| 109 | repo.unrecord_last(options).map_err(|e| match e { |
| 110 | atomic_repository::RepositoryError::Unrecord(msg) |
| 111 | if msg.contains("empty") || msg.contains("Empty") => |
| 112 | { |
| 113 | CliError::InvalidArgument { |
| 114 | message: "View is empty — nothing to unrecord".to_string(), |
| 115 | } |
| 116 | } |
| 117 | other => CliError::Repository(other), |
| 118 | })? |
| 119 | }; |
| 120 | |
| 121 | if outcome.was_dry_run { |
| 122 | for hash in &outcome.unrecorded { |
| 123 | print_warning(&format!("Would unrecord: {}", hash.to_base32())); |
| 124 | } |
| 125 | } else { |
| 126 | for hash in &outcome.unrecorded { |
| 127 | print_success(&format!("Unrecorded: {}", hash.to_base32())); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | Ok(()) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | #[cfg(test)] |
nothing calls this directly
no test coverage detected