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,
)
| 2026 | /// 2. Create .vault/ with defaults → add → record |
| 2027 | /// 3. Status is clean. |
| 2028 | fn 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 { |
no test coverage detected