Insert all changes from another view (the `insert view` subcommand).
(repo: &Repository, args: &ViewArgs)
| 383 | |
| 384 | /// Insert all changes from another view (the `insert view` subcommand). |
| 385 | fn run_view_insert(repo: &Repository, args: &ViewArgs) -> CliResult<()> { |
| 386 | let to_view = args |
| 387 | .to_view |
| 388 | .clone() |
| 389 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 390 | let is_current_view = to_view == repo.current_view(); |
| 391 | |
| 392 | output::print_info(&format!( |
| 393 | "Inserting changes from '{}' to '{}'...", |
| 394 | args.from_view, to_view |
| 395 | )); |
| 396 | |
| 397 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 398 | .with_dependencies(args.deps) |
| 399 | .allow_conflicts(args.allow_conflicts) |
| 400 | .dry_run(args.dry_run); |
| 401 | |
| 402 | let outcome = repo |
| 403 | .insert_from_view(options) |
| 404 | .map_err(|e| CliError::Conflict { |
| 405 | description: e.to_string(), |
| 406 | })?; |
| 407 | |
| 408 | print_cross_view_outcome(&outcome, args.dry_run); |
| 409 | |
| 410 | // Update working copy if we inserted into the current view. |
| 411 | // Collect affected file paths from the inserted changes and only |
| 412 | // materialize those, avoiding a full rematerialization of the |
| 413 | // entire working copy. |
| 414 | if is_current_view && !args.dry_run && outcome.changes_applied > 0 { |
| 415 | let spinner = output::create_spinner("Materializing files for view..."); |
| 416 | |
| 417 | let mut affected_paths = std::collections::HashSet::new(); |
| 418 | for hash in &outcome.applied_hashes { |
| 419 | if let Ok(change) = repo.load_change(hash) { |
| 420 | for op in change.hunks() { |
| 421 | if let Some(p) = op.path() { |
| 422 | affected_paths.insert(p.to_string()); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | let output_result = if affected_paths.is_empty() { |
| 429 | // No path info available (e.g. AddRoot-only changes) — |
| 430 | // fall back to full materialize. |
| 431 | repo.materialize().map_err(|e| { |
| 432 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 433 | })? |
| 434 | } else { |
| 435 | repo.materialize_paths(affected_paths).map_err(|e| { |
| 436 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 437 | })? |
| 438 | }; |
| 439 | |
| 440 | output::finish_success( |
| 441 | &spinner, |
| 442 | &format!( |
no test coverage detected