Preview what would be inserted.
(repo: &Repository, args: &PreviewArgs)
| 417 | |
| 418 | /// Preview what would be inserted. |
| 419 | fn run_preview(repo: &Repository, args: &PreviewArgs) -> CliResult<()> { |
| 420 | let to_view = args |
| 421 | .to_view |
| 422 | .clone() |
| 423 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 424 | |
| 425 | output::print_section("Insert Preview"); |
| 426 | println!(); |
| 427 | println!(" Source view: {}", args.from_view); |
| 428 | println!(" Target view: {}", to_view); |
| 429 | if let Some(ref tag) = args.up_to_tag { |
| 430 | println!(" Up to tag: {}", tag); |
| 431 | } |
| 432 | println!(); |
| 433 | |
| 434 | // Get the changes that would be inserted |
| 435 | let missing = if let Some(ref tag_name) = args.up_to_tag { |
| 436 | // Get changes up to tag, then filter to missing |
| 437 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 438 | .up_to_tag(tag_name) |
| 439 | .dry_run(true); |
| 440 | |
| 441 | let outcome = repo |
| 442 | .insert_from_view(options) |
| 443 | .map_err(|e| CliError::Conflict { |
| 444 | description: e.to_string(), |
| 445 | })?; |
| 446 | |
| 447 | outcome.applied_hashes |
| 448 | } else { |
| 449 | repo.get_missing_changes_between(&args.from_view, Some(&to_view)) |
| 450 | .map_err(|e| CliError::Conflict { |
| 451 | description: e.to_string(), |
| 452 | })? |
| 453 | }; |
| 454 | |
| 455 | if missing.is_empty() { |
| 456 | output::print_success("No changes to insert - target view is up to date."); |
| 457 | } else { |
| 458 | println!("Changes that would be inserted ({}):", missing.len()); |
| 459 | println!(); |
| 460 | for (i, hash) in missing.iter().enumerate() { |
| 461 | // Try to load change header for more info |
| 462 | if let Ok(change) = repo.load_change(hash) { |
| 463 | let message = &change.hashed.header.message; |
| 464 | let short_msg = if message.len() > 50 { |
| 465 | format!("{}...", &message[..47]) |
| 466 | } else { |
| 467 | message.to_string() |
| 468 | }; |
| 469 | println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg); |
| 470 | } else { |
| 471 | println!(" {}. {}", i + 1, format_hash(hash, true)); |
| 472 | } |
| 473 | } |
| 474 | println!(); |
| 475 | output::print_info(&format!( |
| 476 | "Run 'atomic insert from-view {}' to insert these changes.", |
no test coverage detected