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

Function run_preview

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

Preview what would be inserted.

(repo: &Repository, args: &PreviewArgs)

Source from the content-addressed store, hash-verified

560
561/// Preview what would be inserted.
562fn 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(())

Callers 1

runMethod · 0.85

Calls 13

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

Tested by

no test coverage detected