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

Method run

atomic-cli/src/commands/init.rs:502–635  ·  view source on GitHub ↗

Execute the init command. This method: 1. Resolves and validates the target path 2. Validates the view name 3. Creates the directory if it doesn't exist 4. Initializes the repository 5. Creates the initial view 6. Optionally creates a .atomicignore file 7. Prints success message and next steps # Errors Returns an error if: - The path cannot be resolved - A repository already exists at the path

(&self)

Source from the content-addressed store, hash-verified

500 /// - The view name is invalid
501 /// - The repository cannot be created
502 fn run(&self) -> CliResult<()> {
503 // Validate inputs
504 self.validate_view_name()?;
505
506 // Resolve the target path
507 let target_path = self.resolve_path()?;
508
509 // Create the directory if it doesn't exist
510 if !target_path.exists() {
511 std::fs::create_dir_all(&target_path)
512 .map_err(|e| CliError::invalid_path(&target_path, Some(e)))?;
513 }
514
515 // Check if a repository already exists
516 let dot_dir = target_path.join(".atomic");
517 if dot_dir.exists() {
518 return Err(CliError::repository_exists(&target_path));
519 }
520
521 // ── Step 1: Create .atomic/ and the pristine database ────────
522 let mut repo = Repository::init(&target_path).map_err(|e| match e {
523 atomic_repository::RepositoryError::AlreadyExists { .. } => {
524 CliError::repository_exists(&target_path)
525 }
526 other => CliError::Repository(other),
527 })?;
528
529 // Create the initial view if it's different from the default
530 if self.view != atomic_repository::DEFAULT_VIEW {
531 repo.create_view(&self.view).map_err(CliError::Repository)?;
532 repo.align_to_view(&self.view)
533 .map_err(CliError::Repository)?;
534 }
535
536 print_success(&format!(
537 "Initialized empty Atomic repository in {}",
538 dot_dir.display()
539 ));
540 println!("Created view: {}", self.view);
541
542 // ── Step 2: Create .atomicignore → add → record ─────────────
543 //
544 // The .atomicignore MUST contain ".atomic" so the VCS internals
545 // are never tracked. Create it even without --kind (with a minimal
546 // default), then add and record it as the first change.
547 {
548 let ignore_path = target_path.join(".atomicignore");
549 if !ignore_path.exists() {
550 if let Some(ref kind) = self.kind {
551 // Use the language-specific template
552 if let Some(template) = get_ignore_template(kind) {
553 std::fs::write(&ignore_path, template).map_err(CliError::Io)?;
554 println!("Created .atomicignore for {} project", kind);
555 } else {
556 // Unknown kind — write minimal default
557 std::fs::write(&ignore_path, ".atomic\n.git\n").map_err(CliError::Io)?;
558 }
559 } else {

Calls 15

RepositoryClass · 0.85
print_successFunction · 0.85
get_ignore_templateFunction · 0.85
writeFunction · 0.85
print_next_stepsFunction · 0.85
validate_view_nameMethod · 0.80
align_to_viewMethod · 0.80
vault_dirMethod · 0.80
resolve_pathMethod · 0.45
existsMethod · 0.45
create_viewMethod · 0.45