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

Method run

atomic-cli/src/commands/git/import.rs:416–700  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

414
415impl Command for Import {
416 fn run(&self) -> CliResult<()> {
417 // Open Git repository
418 let git_repo = GitRepository::discover(".").map_err(|_| CliError::GitError {
419 message: "Not a git repository (or any parent up to mount point)".to_string(),
420 })?;
421
422 let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError {
423 message: "Git repository has no working directory (bare repository?)".to_string(),
424 })?;
425
426 // Dry run mode
427 if self.dry_run {
428 print_info("Dry run mode - no changes will be made");
429
430 let default_branch = self.get_default_branch(&git_repo)?;
431 let branches = if self.all_branches {
432 self.get_all_branches(&git_repo)?
433 } else {
434 vec![self.branch.clone().unwrap_or(default_branch)]
435 };
436
437 for branch_name in &branches {
438 if let Ok(reference) = git_repo.find_branch(branch_name, git2::BranchType::Local) {
439 if let Some(target) = reference.get().target() {
440 let count = self.count_commits(
441 &git_repo,
442 target,
443 &HashSet::new(),
444 !self.all_branches,
445 )?;
446 print_info(&format!(
447 "Would import {} commits from branch '{}'",
448 count, branch_name
449 ));
450 }
451 }
452 }
453
454 return Ok(());
455 }
456
457 if ensure_git_shadow_excludes(git_repo.path())? {
458 print_info("Configured Git to ignore Atomic local state.");
459 }
460
461 // Check if Atomic repository exists in THIS directory (not parent dirs).
462 // Don't use find_repository_root() — it walks up and might find
463 // ~/.atomic/ (global config dir) which isn't a repo.
464 let repo_exists = workdir.join(".atomic").join("pristine.redb").exists();
465 let mut repo = if repo_exists {
466 Repository::open(workdir).map_err(|e| CliError::Internal(e.into()))?
467 } else {
468 print_info("Initializing Atomic repository...");
469 Repository::init(workdir).map_err(|e| CliError::Internal(e.into()))?
470 };
471
472 let original_view = repo.current_view().to_string();
473 let preserve_current_view = repo_exists && self.incremental;

Callers

nothing calls this directly

Calls 15

print_infoFunction · 0.85
print_hintFunction · 0.85
print_warningFunction · 0.85
reindex_working_copyFunction · 0.85
print_successFunction · 0.85
current_git_branchFunction · 0.85
build_content_indexFunction · 0.85
get_default_branchMethod · 0.80
get_all_branchesMethod · 0.80
count_commitsMethod · 0.80

Tested by

no test coverage detected