(
&self,
repo: &mut Repository,
name: &str,
pre_confirmed: bool,
confirm: F,
)
| 235 | } |
| 236 | |
| 237 | fn execute_with_repo_gated<F>( |
| 238 | &self, |
| 239 | repo: &mut Repository, |
| 240 | name: &str, |
| 241 | pre_confirmed: bool, |
| 242 | confirm: F, |
| 243 | ) -> CliResult<()> |
| 244 | where |
| 245 | F: FnOnce(&str) -> CliResult<bool>, |
| 246 | { |
| 247 | self.validate_and_warn(repo, name, !pre_confirmed, confirm)?; |
| 248 | let working_copy = repo |
| 249 | .require_working_copy_id() |
| 250 | .map_err(CliError::Repository)?; |
| 251 | |
| 252 | // Capture scope before deletion: the mapping reconciliation depends |
| 253 | // on the view's scope (CB-10A). |
| 254 | let scope = repo.get_view_info(name).ok().map(|info| info.scope); |
| 255 | |
| 256 | // CB-10A review R5: deletion eligibility is decided FIRST and only a |
| 257 | // successful deletion may touch mappings. `delete_view` refuses |
| 258 | // Shared views (permanent) and views with children; calling it before |
| 259 | // any mapping effect means a refused delete leaves the mapping bytes, |
| 260 | // Git refs, view rows and operation state untouched. |
| 261 | repo.delete_view(name).map_err(|e| match e { |
| 262 | atomic_repository::RepositoryError::ViewNotFound { name } => { |
| 263 | CliError::ViewNotFound { name } |
| 264 | } |
| 265 | atomic_repository::RepositoryError::CannotDeleteCurrentView { name } => { |
| 266 | CliError::CannotDeleteCurrentView { name } |
| 267 | } |
| 268 | other => CliError::Repository(other), |
| 269 | })?; |
| 270 | |
| 271 | // CB-10A: a Draft's mapping row is removed together with the (now |
| 272 | // deleted) view. A Shared view can never reach this point: deletion |
| 273 | // is refused above and its mapping stays intact. |
| 274 | if let Some(atomic_core::pristine::ViewScope::Draft) = scope { |
| 275 | repo.reconcile_mapping_after_view_delete( |
| 276 | working_copy, |
| 277 | name, |
| 278 | atomic_core::pristine::ViewScope::Draft, |
| 279 | ) |
| 280 | .map_err(CliError::Repository)?; |
| 281 | } |
| 282 | |
| 283 | print_success(&format!("Deleted view: {}", style_view(name))); |
| 284 | |
| 285 | Ok(()) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Tests |
no test coverage detected