Render the operator-facing refusal for a `409` bind outcome. Pure so the advice can be unit-tested without any transport. The advice depends on what the follow-up read of the remote binding found: a genuinely different project keeps the adopt/fork choice, a re-minted document of the same project only leaves `adopt` (fork would mint a third lineage that conflicts the same way), and a server that c
(
local_id: &str,
remote: &ConflictRemote,
server: Option<&BindServerError>,
)
| 189 | /// `409` by reporting the project unbound points at the storage bug instead. |
| 190 | /// The server's own words are quoted whenever it sent any. |
| 191 | fn format_bind_conflict( |
| 192 | local_id: &str, |
| 193 | remote: &ConflictRemote, |
| 194 | server: Option<&BindServerError>, |
| 195 | ) -> String { |
| 196 | let note = server_note(server); |
| 197 | match remote { |
| 198 | ConflictRemote::Bound(document) => { |
| 199 | let remote_id = document |
| 200 | .get("atomic:projectId") |
| 201 | .and_then(|v| v.as_str()) |
| 202 | .map(str::to_owned); |
| 203 | match remote_id { |
| 204 | Some(remote_id) if remote_id != local_id => format!( |
| 205 | "remote project identity is {remote_id}; local is {local_id}. \ |
| 206 | These are different projects — run 'atomic repo identity adopt' \ |
| 207 | to take the remote lineage, or 'atomic repo identity fork' to \ |
| 208 | start a new project, then push accordingly.{note}" |
| 209 | ), |
| 210 | Some(remote_id) => format!( |
| 211 | "the remote is bound to a different document of the same project \ |
| 212 | ({remote_id}) — the bound document was likely re-minted. \ |
| 213 | Run 'atomic repo identity adopt' to take the remote lineage, \ |
| 214 | then push; 'fork' would mint a third lineage that conflicts \ |
| 215 | the same way.{note}" |
| 216 | ), |
| 217 | None => format!( |
| 218 | "the remote is bound to a project-identity document without a \ |
| 219 | readable atomic:projectId, so the divergence cannot be named. \ |
| 220 | Run 'atomic repo identity adopt' to take the remote lineage \ |
| 221 | regardless, then push.{note}" |
| 222 | ), |
| 223 | } |
| 224 | } |
| 225 | ConflictRemote::Unbound => format!( |
| 226 | "the server refused the project-identity bind with a conflict but then \ |
| 227 | reports the project unbound — this contradicts itself and indicates a \ |
| 228 | server-side project-identity ref scoping bug (fixed in \ |
| 229 | atomic-storage#113). Local project identity is {local_id}. Upgrade the \ |
| 230 | storage server and retry the push.{note}" |
| 231 | ), |
| 232 | ConflictRemote::Unknown => format!( |
| 233 | "the push was refused because the remote is already bound to a different \ |
| 234 | project identity, and the remote binding could not be read to name the \ |
| 235 | divergence. Local project identity is {local_id}.{note}" |
| 236 | ), |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /// The server's own words from the `409` body, quoted verbatim; empty when the |
| 241 | /// server sent no readable reason. |