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