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

Method run

atomic-cli/src/commands/init.rs:520–714  ·  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

518 /// - The view name is invalid
519 /// - The repository cannot be created
520 fn run(&self) -> CliResult<()> {
521 // Validate inputs
522 self.validate_view_name()?;
523
524 // Resolve the target path
525 let target_path = self.resolve_path()?;
526
527 // Create the directory if it doesn't exist
528 if !target_path.exists() {
529 std::fs::create_dir_all(&target_path)
530 .map_err(|e| CliError::invalid_path(&target_path, Some(e)))?;
531 }
532
533 // Check if a repository already exists
534 let dot_dir = target_path.join(".atomic");
535 if dot_dir.exists() {
536 return Err(CliError::repository_exists(&target_path));
537 }
538
539 // ── Step 1: Create .atomic/ and the pristine database ────────
540 let mut repo = Repository::init(&target_path).map_err(|e| match e {
541 atomic_repository::RepositoryError::AlreadyExists { .. } => {
542 CliError::repository_exists(&target_path)
543 }
544 other => CliError::Repository(other),
545 })?;
546 repo.ensure_project_identity(atomic_core::kg::project_id::MintReason::Created)
547 .map_err(CliError::Repository)?;
548 let working_copy = repo
549 .require_working_copy_id()
550 .map_err(CliError::Repository)?;
551
552 // Create the initial view if it's different from the default
553 if self.view != atomic_repository::DEFAULT_VIEW {
554 repo.create_view(&self.view).map_err(CliError::Repository)?;
555 repo.align_to_view(working_copy, &self.view)
556 .map_err(CliError::Repository)?;
557 }
558
559 print_success(&format!(
560 "Initialized empty Atomic repository in {}",
561 dot_dir.display()
562 ));
563 println!("Created view: {}", self.view);
564
565 // ── Step 2: Create .atomicignore → add → record ─────────────
566 //
567 // The .atomicignore MUST contain ".atomic" so the VCS internals
568 // are never tracked. Create it even without --kind (with a minimal
569 // default), then add and record it as the first change.
570 {
571 let ignore_path = target_path.join(".atomicignore");
572 if !ignore_path.exists() {
573 if let Some(ref kind) = self.kind {
574 // Use the language-specific template
575 if let Some(template) = get_ignore_template(kind) {
576 std::fs::write(&ignore_path, template).map_err(CliError::Io)?;
577 println!("Created .atomicignore for {} project", kind);

Calls 15

RepositoryClass · 0.85
print_successFunction · 0.85
get_ignore_templateFunction · 0.85
record_vault_stateFunction · 0.85
adopt_git_checkoutFunction · 0.85
print_warningFunction · 0.85
openFunction · 0.85
print_next_stepsFunction · 0.85
validate_view_nameMethod · 0.80
detect_raw_renamesMethod · 0.80