Insert all changes from another view (the `insert view` subcommand).
(
repo: &Repository,
working_copy: WorkingCopyId,
workspace_view: &str,
args: &ViewArgs,
)
| 477 | |
| 478 | /// Insert all changes from another view (the `insert view` subcommand). |
| 479 | fn run_view_insert( |
| 480 | repo: &Repository, |
| 481 | working_copy: WorkingCopyId, |
| 482 | workspace_view: &str, |
| 483 | args: &ViewArgs, |
| 484 | ) -> CliResult<()> { |
| 485 | let to_view = args |
| 486 | .to_view |
| 487 | .clone() |
| 488 | .unwrap_or_else(|| workspace_view.to_string()); |
| 489 | let is_current_view = to_view == workspace_view; |
| 490 | |
| 491 | output::print_info(&format!( |
| 492 | "Inserting changes from '{}' to '{}'...", |
| 493 | args.from_view, to_view |
| 494 | )); |
| 495 | |
| 496 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 497 | .with_dependencies(args.deps) |
| 498 | .allow_conflicts(args.allow_conflicts) |
| 499 | .dry_run(args.dry_run); |
| 500 | |
| 501 | let outcome = repo |
| 502 | .insert_from_view(options) |
| 503 | .map_err(|e| CliError::Conflict { |
| 504 | description: e.to_string(), |
| 505 | })?; |
| 506 | |
| 507 | print_cross_view_outcome(&outcome, args.dry_run); |
| 508 | |
| 509 | // Update working copy if we inserted into the current view. |
| 510 | // Collect affected file paths from the inserted changes and only |
| 511 | // materialize those, avoiding a full rematerialization of the |
| 512 | // entire working copy. |
| 513 | if is_current_view && !args.dry_run && outcome.changes_applied > 0 { |
| 514 | let spinner = output::create_spinner("Materializing files for view..."); |
| 515 | |
| 516 | let affected_paths = outcome.affected_paths.clone(); |
| 517 | |
| 518 | // An empty canonical delta has no filesystem effects. |
| 519 | let output_result = repo |
| 520 | .materialize_paths(working_copy, affected_paths) |
| 521 | .map_err(|e| { |
| 522 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 523 | })?; |
| 524 | |
| 525 | output::finish_success( |
| 526 | &spinner, |
| 527 | &format!( |
| 528 | "{} files updated, {} directories", |
| 529 | output_result.files_written, output_result.directories_created |
| 530 | ), |
| 531 | ); |
| 532 | print_conflict_summary(repo, working_copy); |
| 533 | } |
| 534 | |
| 535 | Ok(()) |
| 536 | } |
no test coverage detected