`repo identity fork` — mint a fresh local identity.
(root: &std::path::Path, json: bool)
| 160 | |
| 161 | /// `repo identity fork` — mint a fresh local identity. |
| 162 | fn fork(root: &std::path::Path, json: bool) -> CliResult<()> { |
| 163 | let repository = atomic_repository::Repository::open(root).map_err(CliError::Repository)?; |
| 164 | let previous = repository |
| 165 | .project_identity() |
| 166 | .map_err(CliError::Repository)? |
| 167 | .map(|record| { |
| 168 | record |
| 169 | .project_id() |
| 170 | .map(|id| id.to_base32()) |
| 171 | .unwrap_or_else(|_| "<unreadable>".to_string()) |
| 172 | }); |
| 173 | let record = repository.fork_identity().map_err(CliError::Repository)?; |
| 174 | let project_id = record.project_id().map(|id| id.to_base32()).map_err(|e| { |
| 175 | CliError::Repository(atomic_repository::RepositoryError::InvalidOperation { |
| 176 | message: e.to_string(), |
| 177 | }) |
| 178 | })?; |
| 179 | let signed = serde_json::from_slice::<serde_json::Value>(&record.object) |
| 180 | .ok() |
| 181 | .and_then(|object| object.get("proof").is_some().then_some(true)) |
| 182 | .unwrap_or(false); |
| 183 | if json { |
| 184 | println!( |
| 185 | "{}", |
| 186 | serde_json::to_string_pretty(&serde_json::json!({ |
| 187 | "project": project_id, |
| 188 | "urn": format!("urn:atomic:project:{project_id}"), |
| 189 | "previous": previous, |
| 190 | "minted": format!("{:?}", record.mint_reason).to_lowercase(), |
| 191 | "signed": signed, |
| 192 | })) |
| 193 | .expect("JSON serialization") |
| 194 | ); |
| 195 | } else { |
| 196 | if let Some(previous) = &previous { |
| 197 | println!("Abandoned local identity {previous}"); |
| 198 | } |
| 199 | println!("Forked project identity {project_id}"); |
| 200 | println!( |
| 201 | "Remotes bound to the previous identity will refuse pushes from this repository." |
| 202 | ); |
| 203 | println!("Create a new project for this lineage and push there."); |
| 204 | } |
| 205 | Ok(()) |
| 206 | } |
| 207 | } |
nothing calls this directly
no test coverage detected