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

Function run_promote_to_parent

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

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)

Source from the content-addressed store, hash-verified

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.
371fn 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));

Callers 1

runMethod · 0.85

Calls 15

print_successFunction · 0.85
print_infoFunction · 0.85
truncate_bytesFunction · 0.85
print_cross_view_outcomeFunction · 0.85
get_view_infoMethod · 0.80
is_sharedMethod · 0.80
with_promptMethod · 0.80
allow_conflictsMethod · 0.80
insert_from_viewMethod · 0.80
cloneMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected