`atomic conflicts` over ListConflicts — render parity: kind, line, sides ride the add-only ConflictInfo fields.
(short: bool)
| 4717 | /// `atomic conflicts` over ListConflicts — render parity: kind, line, |
| 4718 | /// sides ride the add-only ConflictInfo fields. |
| 4719 | pub fn conflicts(short: bool) -> CliResult<bool> { |
| 4720 | let Some(session) = Service::open()? else { |
| 4721 | return Ok(false); |
| 4722 | }; |
| 4723 | let request = pb::ListConflictsRequest { |
| 4724 | repository: Some(session.reference.clone()), |
| 4725 | }; |
| 4726 | let response = session.list_conflicts(request)?; |
| 4727 | |
| 4728 | if short { |
| 4729 | for conflict in &response.conflicts { |
| 4730 | let line = conflict |
| 4731 | .line |
| 4732 | .map(|l| l.to_string()) |
| 4733 | .unwrap_or_else(|| "-".into()); |
| 4734 | println!( |
| 4735 | "{}:{}:{}", |
| 4736 | conflict.path, |
| 4737 | line, |
| 4738 | conflict.kind.as_deref().unwrap_or("-") |
| 4739 | ); |
| 4740 | } |
| 4741 | return Ok(true); |
| 4742 | } |
| 4743 | if response.conflicts.is_empty() { |
| 4744 | print_success("No conflicts."); |
| 4745 | return Ok(true); |
| 4746 | } |
| 4747 | let file_word = if response.conflicts.len() == 1 { |
| 4748 | "file" |
| 4749 | } else { |
| 4750 | "files" |
| 4751 | }; |
| 4752 | // Group by path for the render (the wire is per-record). |
| 4753 | let mut by_path: std::collections::BTreeMap<&str, Vec<&pb::ConflictInfo>> = |
| 4754 | std::collections::BTreeMap::new(); |
| 4755 | for conflict in &response.conflicts { |
| 4756 | by_path.entry(&conflict.path).or_default().push(conflict); |
| 4757 | } |
| 4758 | println!( |
| 4759 | "{}", |
| 4760 | crate::output::warning(&format!("{} conflicted {}:", by_path.len(), file_word)) |
| 4761 | ); |
| 4762 | println!(); |
| 4763 | for (path, records) in &by_path { |
| 4764 | println!("\t{path}"); |
| 4765 | for record in records { |
| 4766 | let where_ = match record.line { |
| 4767 | Some(line) => format!("line {line}"), |
| 4768 | None => "unknown line".to_string(), |
| 4769 | }; |
| 4770 | let kind = record.kind.as_deref().unwrap_or("conflict"); |
| 4771 | if record.sides.is_empty() { |
| 4772 | println!("\t {kind} conflict at {where_}"); |
| 4773 | } else { |
| 4774 | let sides = record |
| 4775 | .sides |
| 4776 | .iter() |
no test coverage detected