(&self)
| 26 | |
| 27 | impl Command for Init { |
| 28 | fn run(&self) -> CliResult<()> { |
| 29 | // Route every form through the service layer: vault init operates |
| 30 | // inside an EXISTING repository (it requires one), so it routes |
| 31 | // normally via the daemon (the handler runs the exact local flow). |
| 32 | if crate::commands::rpc::vault_init()? { |
| 33 | return Ok(()); |
| 34 | } |
| 35 | let root = find_repository_root()?; |
| 36 | let mut repo = Repository::open(&root).map_err(|e| CliError::InvalidRepository { |
| 37 | reason: e.to_string(), |
| 38 | })?; |
| 39 | |
| 40 | let working_copy = repo |
| 41 | .require_working_copy_id() |
| 42 | .map_err(CliError::Repository)?; |
| 43 | |
| 44 | if repo.has_vault().unwrap_or(false) { |
| 45 | print_info("Vault is already initialized"); |
| 46 | return Ok(()); |
| 47 | } |
| 48 | |
| 49 | repo.init_vault().map_err(CliError::Repository)?; |
| 50 | print_info(&format!( |
| 51 | "Initialized vault at {}", |
| 52 | repo.vault_dir().display() |
| 53 | )); |
| 54 | |
| 55 | // Add all vault files to tracking |
| 56 | let vault_dir = repo.vault_dir(); |
| 57 | if vault_dir.exists() { |
| 58 | add_vault_files_recursive(&repo, working_copy, &vault_dir)?; |
| 59 | } |
| 60 | |
| 61 | // Record vault files as their own change |
| 62 | let header = atomic_core::change::ChangeHeader::new("Initialize vault"); |
| 63 | let options = atomic_repository::RecordOptions::new() |
| 64 | .add_path(".vault") |
| 65 | .detect_raw_renames(false); |
| 66 | match repo.record(working_copy, header, options) { |
| 67 | Ok(_) => print_success("Recorded vault defaults"), |
| 68 | Err(atomic_repository::RecordError::NothingToRecord) => {} |
| 69 | Err(e) => log::warn!("Failed to record vault files: {}", e), |
| 70 | } |
| 71 | |
| 72 | Ok(()) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | fn add_vault_files_recursive( |
nothing calls this directly
no test coverage detected