Promote the current view's changes into its parent view. This is the behavior of a bare `atomic insert` (no change hash and no subcommand). The source is always the current view; the target defaults to the current view's parent but can be overridden with `--to`/`--view`. The working copy is intentionally NOT rematerialized: the target view is not checked out, so the current view's on-disk state
(repo: &Repository, workspace_view: &str, args: &Insert)
| 369 | /// The working copy is intentionally NOT rematerialized: the target view is |
| 370 | /// not checked out, so the current view's on-disk state is unchanged. |
| 371 | fn run_promote_to_parent(repo: &Repository, workspace_view: &str, args: &Insert) -> CliResult<()> { |
| 372 | let source = workspace_view.to_string(); |
| 373 | let source_info = repo |
| 374 | .get_view_info(&source) |
| 375 | .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 376 | |
| 377 | // Resolve the target: explicit --to/--view, else the current view's parent. |
| 378 | let target = match args.view.as_deref() { |
| 379 | Some(v) => v.to_string(), |
| 380 | None => source_info |
| 381 | .parent_name |
| 382 | .clone() |
| 383 | .ok_or_else(|| CliError::InvalidArgument { |
| 384 | message: format!( |
| 385 | "'{source}' is a root view — there is no parent to insert into.\n \ |
| 386 | Use 'atomic insert from-view <source>' or pass --to <view> \ |
| 387 | to choose a target." |
| 388 | ), |
| 389 | })?, |
| 390 | }; |
| 391 | |
| 392 | if target == source { |
| 393 | return Err(CliError::InvalidArgument { |
| 394 | message: format!( |
| 395 | "Source and target are the same view ('{source}'). \ |
| 396 | Pass --to <view> to insert somewhere else." |
| 397 | ), |
| 398 | }); |
| 399 | } |
| 400 | |
| 401 | // Figure out what would move so we can show a count and short-circuit. |
| 402 | let missing = repo |
| 403 | .get_missing_changes_between(&source, Some(&target)) |
| 404 | .map_err(|e| CliError::Conflict { |
| 405 | description: e.to_string(), |
| 406 | })?; |
| 407 | |
| 408 | if missing.is_empty() { |
| 409 | output::print_success(&format!( |
| 410 | "Already even with '{target}' — nothing to insert." |
| 411 | )); |
| 412 | return Ok(()); |
| 413 | } |
| 414 | |
| 415 | output::print_info(&format!( |
| 416 | "Inserting {} change(s): {source} → {target}", |
| 417 | missing.len() |
| 418 | )); |
| 419 | |
| 420 | // Dry run: list the changes and stop before mutating. |
| 421 | if args.dry_run { |
| 422 | println!(); |
| 423 | for (i, hash) in missing.iter().enumerate() { |
| 424 | if let Ok(change) = repo.load_change(hash) { |
| 425 | let short_msg = output::truncate_bytes(&change.hashed.header.message, 50); |
| 426 | println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg); |
| 427 | } else { |
| 428 | println!(" {}. {}", i + 1, format_hash(hash, true)); |
no test coverage detected