Preview what would be inserted.
(repo: &Repository, workspace_view: &str, args: &PreviewArgs)
| 648 | |
| 649 | /// Preview what would be inserted. |
| 650 | fn run_preview(repo: &Repository, workspace_view: &str, args: &PreviewArgs) -> CliResult<()> { |
| 651 | let to_view = args |
| 652 | .to_view |
| 653 | .clone() |
| 654 | .unwrap_or_else(|| workspace_view.to_string()); |
| 655 | |
| 656 | output::print_section("Insert Preview"); |
| 657 | println!(); |
| 658 | println!(" Source view: {}", args.from_view); |
| 659 | println!(" Target view: {}", to_view); |
| 660 | if let Some(ref tag) = args.up_to_tag { |
| 661 | println!(" Up to tag: {}", tag); |
| 662 | } |
| 663 | println!(); |
| 664 | |
| 665 | // Get the changes that would be inserted |
| 666 | let missing = if let Some(ref tag_name) = args.up_to_tag { |
| 667 | // Get changes up to tag, then filter to missing |
| 668 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 669 | .up_to_tag(tag_name) |
| 670 | .dry_run(true); |
| 671 | |
| 672 | let outcome = repo |
| 673 | .insert_from_view(options) |
| 674 | .map_err(|e| CliError::Conflict { |
| 675 | description: e.to_string(), |
| 676 | })?; |
| 677 | |
| 678 | outcome.applied_hashes |
| 679 | } else { |
| 680 | repo.get_missing_changes_between(&args.from_view, Some(&to_view)) |
| 681 | .map_err(|e| CliError::Conflict { |
| 682 | description: e.to_string(), |
| 683 | })? |
| 684 | }; |
| 685 | |
| 686 | if missing.is_empty() { |
| 687 | output::print_success("No changes to insert - target view is up to date."); |
| 688 | } else { |
| 689 | println!("Changes that would be inserted ({}):", missing.len()); |
| 690 | println!(); |
| 691 | for (i, hash) in missing.iter().enumerate() { |
| 692 | // Try to load change header for more info |
| 693 | if let Ok(change) = repo.load_change(hash) { |
| 694 | let short_msg = output::truncate_bytes(&change.hashed.header.message, 50); |
| 695 | println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg); |
| 696 | } else { |
| 697 | println!(" {}. {}", i + 1, format_hash(hash, true)); |
| 698 | } |
| 699 | } |
| 700 | println!(); |
| 701 | output::print_info(&format!( |
| 702 | "Run 'atomic insert view {}' to insert these changes.", |
| 703 | args.from_view |
| 704 | )); |
| 705 | } |
| 706 | |
| 707 | Ok(()) |
no test coverage detected