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

Function run_single_insert

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

Insert a single change by hash.

(
    repo: &Repository,
    working_copy: WorkingCopyId,
    workspace_view: &str,
    change_str: &str,
    args: &Insert,
)

Source from the content-addressed store, hash-verified

301
302/// Insert a single change by hash.
303fn run_single_insert(
304 repo: &Repository,
305 working_copy: WorkingCopyId,
306 workspace_view: &str,
307 change_str: &str,
308 args: &Insert,
309) -> CliResult<()> {
310 let hash = parse_change_hash(repo, change_str)?;
311 let target_view = args
312 .view
313 .clone()
314 .unwrap_or_else(|| workspace_view.to_string());
315 let is_current_view = target_view == workspace_view;
316
317 let options = InsertOptions::default()
318 .apply_deps(args.deps)
319 .allow_conflict(args.allow_conflicts)
320 .view(&target_view);
321
322 if args.dry_run {
323 output::print_info(&format!(
324 "Dry run: would insert change {} into '{}'.",
325 format_hash(&hash, true),
326 target_view
327 ));
328 return Ok(());
329 }
330
331 output::print_info(&format!("Inserting change {}...", format_hash(&hash, true)));
332
333 let outcome = if args.deps {
334 repo.insert_change_rec(&hash, options)
335 } else {
336 repo.insert_change(&hash, options)
337 }
338 .map_err(|e| CliError::Conflict {
339 description: e.to_string(),
340 })?;
341
342 print_insert_outcome(
343 &outcome.stats.applied_hashes,
344 outcome.new_state,
345 outcome.has_conflicts,
346 );
347
348 // Update working copy if we inserted into its desired view.
349 if is_current_view && !outcome.stats.applied_hashes.is_empty() {
350 let output_result = repo.materialize(working_copy).map_err(|e| {
351 CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e))
352 })?;
353 output::print_success(&format!(
354 "{} files updated, {} directories",
355 output_result.files_written, output_result.directories_created
356 ));
357 print_conflict_summary(repo, working_copy);
358 }
359
360 Ok(())

Callers 1

runMethod · 0.85

Calls 13

print_infoFunction · 0.85
print_insert_outcomeFunction · 0.85
print_successFunction · 0.85
print_conflict_summaryFunction · 0.85
allow_conflictMethod · 0.80
apply_depsMethod · 0.80
insert_change_recMethod · 0.80
parse_change_hashFunction · 0.70
cloneMethod · 0.45
viewMethod · 0.45
insert_changeMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected