MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run_preview

Function run_preview

atomic-cli/src/commands/insert.rs:663–721  ·  view source on GitHub ↗

Preview what would be inserted.

(repo: &Repository, workspace_view: &str, args: &PreviewArgs)

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.85

Calls 12

print_sectionFunction · 0.85
print_successFunction · 0.85
truncate_bytesFunction · 0.85
print_infoFunction · 0.85
up_to_tagMethod · 0.80
insert_from_viewMethod · 0.80
cloneMethod · 0.45
dry_runMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
load_changeMethod · 0.45

Tested by

no test coverage detected