Insert specific change(s) by hash (the `insert change` subcommand).
(
repo: &Repository,
working_copy: WorkingCopyId,
workspace_view: &str,
args: &ChangeArgs,
)
| 599 | |
| 600 | /// Insert specific change(s) by hash (the `insert change` subcommand). |
| 601 | fn run_change_insert( |
| 602 | repo: &Repository, |
| 603 | working_copy: WorkingCopyId, |
| 604 | workspace_view: &str, |
| 605 | args: &ChangeArgs, |
| 606 | ) -> CliResult<()> { |
| 607 | let to_view = args |
| 608 | .to_view |
| 609 | .clone() |
| 610 | .unwrap_or_else(|| workspace_view.to_string()); |
| 611 | let is_current_view = to_view == workspace_view; |
| 612 | |
| 613 | // Parse all change hashes |
| 614 | let mut hashes = Vec::new(); |
| 615 | for change_str in &args.changes { |
| 616 | let hash = parse_change_hash(repo, change_str)?; |
| 617 | hashes.push(hash); |
| 618 | } |
| 619 | |
| 620 | output::print_info(&format!( |
| 621 | "Cherry-picking {} change(s) to '{}'...", |
| 622 | hashes.len(), |
| 623 | to_view |
| 624 | )); |
| 625 | |
| 626 | let outcome = |
| 627 | repo.cherry_pick(&hashes, "", Some(&to_view)) |
| 628 | .map_err(|e| CliError::Conflict { |
| 629 | description: e.to_string(), |
| 630 | })?; |
| 631 | |
| 632 | print_cross_view_outcome(&outcome, false); |
| 633 | |
| 634 | // Update working copy if we inserted into its desired view. |
| 635 | if is_current_view && outcome.changes_applied > 0 { |
| 636 | let output_result = repo.materialize(working_copy).map_err(|e| { |
| 637 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 638 | })?; |
| 639 | output::print_success(&format!( |
| 640 | "{} files updated, {} directories", |
| 641 | output_result.files_written, output_result.directories_created |
| 642 | )); |
| 643 | print_conflict_summary(repo, working_copy); |
| 644 | } |
| 645 | |
| 646 | Ok(()) |
| 647 | } |
| 648 | |
| 649 | /// Preview what would be inserted. |
| 650 | fn run_preview(repo: &Repository, workspace_view: &str, args: &PreviewArgs) -> CliResult<()> { |
no test coverage detected