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

Function add

atomic-cli/src/commands/rpc.rs:540–605  ·  view source on GitHub ↗

`atomic add` over AddFiles — every form: dry-run/force/directory/ no-recursive ride the wire, and internal `.atomic` paths route too (the repository's ignore rules treat them like any other ignored path — the tolerant per-path report carries the skip).

(args: &super::add::Add)

Source from the content-addressed store, hash-verified

538/// (the repository's ignore rules treat them like any other ignored
539/// path — the tolerant per-path report carries the skip).
540pub fn add(args: &super::add::Add) -> CliResult<bool> {
541 let Some(session) = Service::open()? else {
542 return Ok(false);
543 };
544 let root = crate::commands::find_repository_root()?;
545 let paths = if args.all {
546 // `add --all` composes an untracked read first — the same read the
547 // CLI does today, over the service layer.
548 let request = pb::StatusRequest {
549 repository: Some(session.reference.clone()),
550 options: None,
551 };
552 let status = session.status(request)?;
553 status
554 .files
555 .iter()
556 .filter(|file| file.status == pb::FileStatus::Untracked as i32)
557 .map(|file| file.path.clone())
558 .collect()
559 } else {
560 args.files.clone()
561 };
562 let request = pb::AddFilesRequest {
563 repository: Some(session.reference.clone()),
564 meta: request_meta(),
565 paths: paths.iter().map(|path| relativize(path, &root)).collect(),
566 expected: None,
567 dry_run: args.dry_run,
568 force: args.force,
569 directory: args.directory,
570 no_recursive: args.no_recursive,
571 };
572 let response = session.add_files(request)?;
573 for path in &paths {
574 println!("Adding: {path}");
575 }
576 if response.dry_run {
577 for path in &response.would_add {
578 println!("Would add: {path}");
579 }
580 for path in &response.skipped_tracked {
581 println!("Skipping: {path} (already tracked)");
582 }
583 for path in &response.skipped_ignored {
584 println!("Skipping: {path} (ignored)");
585 }
586 for path in &response.failed_paths {
587 println!("Error: {path} - could not be added");
588 }
589 println!("Would add {} file(s)", response.would_add.len());
590 return Ok(true);
591 }
592 if response.tracked > 0 {
593 let requested = paths
594 .iter()
595 .map(std::path::PathBuf::from)
596 .collect::<Vec<_>>();
597 if let Err(error) = super::add::finish_service_add(&root, &requested) {

Callers 11

runMethod · 0.70
test_inode_update_addFunction · 0.50
test_inode_update_hashFunction · 0.50
test_inode_update_debugFunction · 0.50
test_add_inode_updateFunction · 0.50
test_stats_populatedFunction · 0.50
test_recorded_into_partsFunction · 0.50
summarizeFunction · 0.50

Calls 11

openFunction · 0.85
find_repository_rootFunction · 0.85
relativizeFunction · 0.85
finish_service_addFunction · 0.85
print_warningFunction · 0.85
request_metaFunction · 0.70
cloneMethod · 0.45
statusMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
add_filesMethod · 0.45

Tested by 9

test_inode_update_addFunction · 0.40
test_inode_update_hashFunction · 0.40
test_inode_update_debugFunction · 0.40
test_add_inode_updateFunction · 0.40
test_stats_populatedFunction · 0.40
test_recorded_into_partsFunction · 0.40