Insert specific change(s) by hash (the `insert change` subcommand).
(repo: &Repository, args: &ChangeArgs)
| 518 | |
| 519 | /// Insert specific change(s) by hash (the `insert change` subcommand). |
| 520 | fn run_change_insert(repo: &Repository, args: &ChangeArgs) -> CliResult<()> { |
| 521 | let to_view = args |
| 522 | .to_view |
| 523 | .clone() |
| 524 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 525 | let is_current_view = to_view == repo.current_view(); |
| 526 | |
| 527 | // Parse all change hashes |
| 528 | let mut hashes = Vec::new(); |
| 529 | for change_str in &args.changes { |
| 530 | let hash = parse_change_hash(repo, change_str)?; |
| 531 | hashes.push(hash); |
| 532 | } |
| 533 | |
| 534 | output::print_info(&format!( |
| 535 | "Cherry-picking {} change(s) to '{}'...", |
| 536 | hashes.len(), |
| 537 | to_view |
| 538 | )); |
| 539 | |
| 540 | let outcome = |
| 541 | repo.cherry_pick(&hashes, "", Some(&to_view)) |
| 542 | .map_err(|e| CliError::Conflict { |
| 543 | description: e.to_string(), |
| 544 | })?; |
| 545 | |
| 546 | print_cross_view_outcome(&outcome, false); |
| 547 | |
| 548 | // Update working copy if we inserted into the current view |
| 549 | if is_current_view && outcome.changes_applied > 0 { |
| 550 | let output_result = repo.materialize().map_err(|e| { |
| 551 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 552 | })?; |
| 553 | output::print_success(&format!( |
| 554 | "{} files updated, {} directories", |
| 555 | output_result.files_written, output_result.directories_created |
| 556 | )); |
| 557 | } |
| 558 | |
| 559 | Ok(()) |
| 560 | } |
| 561 | |
| 562 | /// Preview what would be inserted. |
| 563 | fn run_preview(repo: &Repository, args: &PreviewArgs) -> CliResult<()> { |
no test coverage detected