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

Function run_promote_to_parent

atomic-cli/src/commands/insert.rs:271–381  ·  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, args: &Insert)

Source from the content-addressed store, hash-verified

269/// The working copy is intentionally NOT rematerialized: the target view is
270/// not checked out, so the current view's on-disk state is unchanged.
271fn run_promote_to_parent(repo: &Repository, args: &Insert) -> CliResult<()> {
272 let source = repo.current_view().to_string();
273 let source_info = repo
274 .get_view_info(&source)
275 .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?;
276
277 // Resolve the target: explicit --to/--view, else the current view's parent.
278 let target = match args.view.as_deref() {
279 Some(v) => v.to_string(),
280 None => source_info
281 .parent_name
282 .clone()
283 .ok_or_else(|| CliError::InvalidArgument {
284 message: format!(
285 "'{source}' is a root view — there is no parent to insert into.\n \
286 Use 'atomic insert from-view <source>' or pass --to <view> \
287 to choose a target."
288 ),
289 })?,
290 };
291
292 if target == source {
293 return Err(CliError::InvalidArgument {
294 message: format!(
295 "Source and target are the same view ('{source}'). \
296 Pass --to <view> to insert somewhere else."
297 ),
298 });
299 }
300
301 // Figure out what would move so we can show a count and short-circuit.
302 let missing = repo
303 .get_missing_changes_between(&source, Some(&target))
304 .map_err(|e| CliError::Conflict {
305 description: e.to_string(),
306 })?;
307
308 if missing.is_empty() {
309 output::print_success(&format!(
310 "Already even with '{target}' — nothing to insert."
311 ));
312 return Ok(());
313 }
314
315 output::print_info(&format!(
316 "Inserting {} change(s): {source} → {target}",
317 missing.len()
318 ));
319
320 // Dry run: list the changes and stop before mutating.
321 if args.dry_run {
322 println!();
323 for (i, hash) in missing.iter().enumerate() {
324 if let Ok(change) = repo.load_change(hash) {
325 let message = &change.hashed.header.message;
326 let short_msg = if message.len() > 50 {
327 format!("{}...", &message[..47])
328 } else {

Callers 1

runMethod · 0.85

Calls 15

print_successFunction · 0.85
print_infoFunction · 0.85
print_cross_view_outcomeFunction · 0.85
current_viewMethod · 0.80
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