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

Function init_atomicignore_and_vault

atomic-cli/src/commands/git/import.rs:2028–2141  ·  view source on GitHub ↗

Create .atomicignore and initialize vault AFTER git import + materialize. This runs post-import so the import's materialize step can't stomp the vault files' tracked state. The sequence is: 1. Create .atomicignore (auto-detect project type) → add → record 2. Create .vault/ with defaults → add → record 3. Status is clean.

(
    repo: &mut Repository,
    workdir: &std::path::Path,
    kind: Option<&str>,
    no_vault: bool,
    working_copy: WorkingCopyId,
)

Source from the content-addressed store, hash-verified

2026/// 2. Create .vault/ with defaults → add → record
2027/// 3. Status is clean.
2028fn init_atomicignore_and_vault(
2029 repo: &mut Repository,
2030 workdir: &std::path::Path,
2031 kind: Option<&str>,
2032 no_vault: bool,
2033 working_copy: WorkingCopyId,
2034) -> CliResult<()> {
2035 // Step 1: .atomicignore
2036 {
2037 let ignore_path = workdir.join(".atomicignore");
2038 if !ignore_path.exists() {
2039 // Use explicit --kind if provided, otherwise auto-detect from project files
2040 let ignore_content = if let Some(k) = kind {
2041 super::super::init::get_ignore_template(k).unwrap_or(".atomic\n.git\n")
2042 } else if workdir.join("Cargo.toml").exists() {
2043 super::super::init::get_ignore_template("rust").unwrap_or(".atomic\n.git\n")
2044 } else if workdir.join("package.json").exists() {
2045 super::super::init::get_ignore_template("node").unwrap_or(".atomic\n.git\n")
2046 } else if workdir.join("go.mod").exists() {
2047 super::super::init::get_ignore_template("go").unwrap_or(".atomic\n.git\n")
2048 } else if workdir.join("setup.py").exists() || workdir.join("pyproject.toml").exists() {
2049 super::super::init::get_ignore_template("python").unwrap_or(".atomic\n.git\n")
2050 } else {
2051 ".atomic\n.git\n"
2052 };
2053 let _ = std::fs::write(&ignore_path, ignore_content);
2054 }
2055
2056 let _ = repo.add(
2057 working_copy,
2058 ".atomicignore",
2059 atomic_repository::TrackingOptions::default(),
2060 );
2061 let header = atomic_core::change::ChangeHeader::new("Initialize repository");
2062 let options = atomic_repository::RecordOptions::new()
2063 .add_path(".atomicignore")
2064 .detect_raw_renames(false);
2065 match repo.record(working_copy, header, options) {
2066 Ok(_) => print_info("Recorded .atomicignore"),
2067 Err(atomic_repository::RecordError::NothingToRecord) => {}
2068 Err(e) => log::warn!("Failed to record .atomicignore: {}", e),
2069 }
2070 }
2071
2072 // Step 2: Vault (unless --no-vault)
2073 if no_vault {
2074 return Ok(());
2075 }
2076
2077 // A pre-existing `.vault/` working copy is user work — in a colocated
2078 // repository it arrived with the Git checkout. Hydrate the vault
2079 // tables from disk and install NOTHING: the on-disk file set is
2080 // authoritative. (Creating missing default files here would add
2081 // untracked paths that diverge the manifest projection from the Git
2082 // HEAD tree under the tracked-vault policy; a fresh repository
2083 // without `.vault/` still gets the full default vault below.)
2084 let existing_vault = repo.vault_dir().exists();
2085 let init_result = if existing_vault {

Callers 1

run_importMethod · 0.85

Calls 12

get_ignore_templateFunction · 0.85
print_infoFunction · 0.85
add_dir_recursiveFunction · 0.85
detect_raw_renamesMethod · 0.80
vault_dirMethod · 0.80
writeFunction · 0.50
existsMethod · 0.45
addMethod · 0.45
add_pathMethod · 0.45
recordMethod · 0.45
init_vaultMethod · 0.45

Tested by

no test coverage detected