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:2088–2202  ·  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,
    git_tracks_atomic_ignore: bool,
)

Source from the content-addressed store, hash-verified

2086/// 2. Create .vault/ with defaults → add → record
2087/// 3. Status is clean.
2088fn init_atomicignore_and_vault(
2089 repo: &mut Repository,
2090 workdir: &std::path::Path,
2091 kind: Option<&str>,
2092 no_vault: bool,
2093 working_copy: WorkingCopyId,
2094 git_tracks_atomic_ignore: bool,
2095) -> CliResult<()> {
2096 // Git import already recorded a tracked .atomicignore.
2097 if !git_tracks_atomic_ignore {
2098 let ignore_path = workdir.join(".atomicignore");
2099 if !ignore_path.exists() {
2100 // Use explicit --kind if provided, otherwise auto-detect from project files
2101 let ignore_content = if let Some(k) = kind {
2102 super::super::init::get_ignore_template(k).unwrap_or(".atomic\n.git\n")
2103 } else if workdir.join("Cargo.toml").exists() {
2104 super::super::init::get_ignore_template("rust").unwrap_or(".atomic\n.git\n")
2105 } else if workdir.join("package.json").exists() {
2106 super::super::init::get_ignore_template("node").unwrap_or(".atomic\n.git\n")
2107 } else if workdir.join("go.mod").exists() {
2108 super::super::init::get_ignore_template("go").unwrap_or(".atomic\n.git\n")
2109 } else if workdir.join("setup.py").exists() || workdir.join("pyproject.toml").exists() {
2110 super::super::init::get_ignore_template("python").unwrap_or(".atomic\n.git\n")
2111 } else {
2112 ".atomic\n.git\n"
2113 };
2114 let _ = std::fs::write(&ignore_path, ignore_content);
2115 }
2116
2117 let _ = repo.add(
2118 working_copy,
2119 ".atomicignore",
2120 atomic_repository::TrackingOptions::default(),
2121 );
2122 let header = atomic_core::change::ChangeHeader::new("Initialize repository");
2123 let options = atomic_repository::RecordOptions::new()
2124 .add_path(".atomicignore")
2125 .detect_raw_renames(false);
2126 match repo.record(working_copy, header, options) {
2127 Ok(_) => print_info("Recorded .atomicignore"),
2128 Err(atomic_repository::RecordError::NothingToRecord) => {}
2129 Err(e) => log::warn!("Failed to record .atomicignore: {}", e),
2130 }
2131 }
2132
2133 // Step 2: Vault (unless --no-vault)
2134 if no_vault {
2135 return Ok(());
2136 }
2137
2138 // A pre-existing `.vault/` working copy is user work — in a colocated
2139 // repository it arrived with the Git checkout. Hydrate the vault
2140 // tables from disk and install NOTHING: the on-disk file set is
2141 // authoritative. (Creating missing default files here would add
2142 // untracked paths that diverge the manifest projection from the Git
2143 // HEAD tree under the tracked-vault policy; a fresh repository
2144 // without `.vault/` still gets the full default vault below.)
2145 let existing_vault = repo.vault_dir().exists();

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