(&self)
| 83 | |
| 84 | impl Command for Unrecord { |
| 85 | fn run(&self) -> CliResult<()> { |
| 86 | let repo_root = find_repository_root()?; |
| 87 | let repo = Repository::open(&repo_root).map_err(|e| match e { |
| 88 | atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound { |
| 89 | searched_path: path.into(), |
| 90 | }, |
| 91 | other => CliError::Repository(other), |
| 92 | })?; |
| 93 | |
| 94 | let options = if self.dry_run { |
| 95 | UnrecordOptions::dry_run() |
| 96 | } else { |
| 97 | UnrecordOptions::new() |
| 98 | }; |
| 99 | |
| 100 | let outcome = if let Some(ref prefix) = self.change { |
| 101 | let hash = resolve_change(&repo, prefix)?; |
| 102 | repo.unrecord(&hash, options) |
| 103 | .map_err(CliError::Repository)? |
| 104 | } else { |
| 105 | // Unrecord the most recent change |
| 106 | repo.unrecord_last(options).map_err(|e| match e { |
| 107 | atomic_repository::RepositoryError::Unrecord(msg) |
| 108 | if msg.contains("empty") || msg.contains("Empty") => |
| 109 | { |
| 110 | CliError::InvalidArgument { |
| 111 | message: "View is empty — nothing to unrecord".to_string(), |
| 112 | } |
| 113 | } |
| 114 | other => CliError::Repository(other), |
| 115 | })? |
| 116 | }; |
| 117 | |
| 118 | if outcome.was_dry_run { |
| 119 | for hash in &outcome.unrecorded { |
| 120 | print_warning(&format!("Would unrecord: {}", hash.to_base32())); |
| 121 | } |
| 122 | } else { |
| 123 | for hash in &outcome.unrecorded { |
| 124 | print_success(&format!("Unrecorded: {}", hash.to_base32())); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | Ok(()) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | fn resolve_change(repo: &Repository, prefix: &str) -> CliResult<Hash> { |
nothing calls this directly
no test coverage detected