Preview what would be inserted.
(repo: &Repository, args: &PreviewArgs)
| 560 | |
| 561 | /// Preview what would be inserted. |
| 562 | fn run_preview(repo: &Repository, args: &PreviewArgs) -> CliResult<()> { |
| 563 | let to_view = args |
| 564 | .to_view |
| 565 | .clone() |
| 566 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 567 | |
| 568 | output::print_section("Insert Preview"); |
| 569 | println!(); |
| 570 | println!(" Source view: {}", args.from_view); |
| 571 | println!(" Target view: {}", to_view); |
| 572 | if let Some(ref tag) = args.up_to_tag { |
| 573 | println!(" Up to tag: {}", tag); |
| 574 | } |
| 575 | println!(); |
| 576 | |
| 577 | // Get the changes that would be inserted |
| 578 | let missing = if let Some(ref tag_name) = args.up_to_tag { |
| 579 | // Get changes up to tag, then filter to missing |
| 580 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 581 | .up_to_tag(tag_name) |
| 582 | .dry_run(true); |
| 583 | |
| 584 | let outcome = repo |
| 585 | .insert_from_view(options) |
| 586 | .map_err(|e| CliError::Conflict { |
| 587 | description: e.to_string(), |
| 588 | })?; |
| 589 | |
| 590 | outcome.applied_hashes |
| 591 | } else { |
| 592 | repo.get_missing_changes_between(&args.from_view, Some(&to_view)) |
| 593 | .map_err(|e| CliError::Conflict { |
| 594 | description: e.to_string(), |
| 595 | })? |
| 596 | }; |
| 597 | |
| 598 | if missing.is_empty() { |
| 599 | output::print_success("No changes to insert - target view is up to date."); |
| 600 | } else { |
| 601 | println!("Changes that would be inserted ({}):", missing.len()); |
| 602 | println!(); |
| 603 | for (i, hash) in missing.iter().enumerate() { |
| 604 | // Try to load change header for more info |
| 605 | if let Ok(change) = repo.load_change(hash) { |
| 606 | let short_msg = output::truncate_bytes(&change.hashed.header.message, 50); |
| 607 | println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg); |
| 608 | } else { |
| 609 | println!(" {}. {}", i + 1, format_hash(hash, true)); |
| 610 | } |
| 611 | } |
| 612 | println!(); |
| 613 | output::print_info(&format!( |
| 614 | "Run 'atomic insert view {}' to insert these changes.", |
| 615 | args.from_view |
| 616 | )); |
| 617 | } |
| 618 | |
| 619 | Ok(()) |
no test coverage detected