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

Method run

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

Source from the content-addressed store, hash-verified

555
556impl Command for Import {
557 fn run(&self) -> CliResult<()> {
558 // Open Git repository
559 let git_repo = GitRepository::discover(".").map_err(|_| CliError::GitError {
560 message: "Not a git repository (or any parent up to mount point)".to_string(),
561 })?;
562
563 let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError {
564 message: "Git repository has no working directory (bare repository?)".to_string(),
565 })?;
566
567 // Dry run mode
568 if self.dry_run {
569 print_info("Dry run mode - no changes will be made");
570
571 let default_branch = self.get_default_branch(&git_repo)?;
572 let branches = if self.all_branches {
573 self.get_all_branches(&git_repo)?
574 } else {
575 vec![self.branch.clone().unwrap_or(default_branch)]
576 };
577
578 // For an incremental forecast, open the existing Atomic repo
579 // read-only so we can subtract what each branch's view already
580 // contains. A fresh (not-yet-initialized) repo has nothing
581 // imported, so the forecast is the full history — which is correct.
582 let repo = if self.incremental && workdir.join(".atomic").join("pristine.redb").exists()
583 {
584 Repository::open_readonly(workdir).ok()
585 } else {
586 None
587 };
588
589 for branch_name in &branches {
590 if let Ok(reference) = git_repo.find_branch(branch_name, git2::BranchType::Local) {
591 if let Some(target) = reference.get().target() {
592 // Compute the same incremental markers the real import
593 // would use for this branch's view (without repairing
594 // the index — a dry run writes nothing).
595 let (imported_shas, known_states) = match &repo {
596 Some(repo) if repo.view_exists(branch_name).unwrap_or(false) => {
597 self.get_incremental_markers(repo, branch_name, false)?
598 }
599 _ => (HashSet::new(), HashSet::new()),
600 };
601
602 let count = self.count_commits(
603 &git_repo,
604 target,
605 &imported_shas,
606 &known_states,
607 branch_name,
608 !self.all_branches,
609 )?;
610 print_info(&format!(
611 "Would import {} commit{} from branch '{}'",
612 count,
613 if count == 1 { "" } else { "s" },
614 branch_name

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
view_existsMethod · 0.80

Tested by

no test coverage detected