Build a human-readable summary of file changes from the repository status. Groups changes by kind and lists filenames (not full paths) to keep the message concise. Examples: - `"Add src/main.rs, Cargo.toml"` - `"Modify auth.rs; delete old_config.toml"` - `"Add 12 files"` - `"Modify handler.rs; add 5 files"`
(
status: &RepositoryStatus,
untracked_paths: &[String],
)
| 287 | /// - `"Add 12 files"` |
| 288 | /// - `"Modify handler.rs; add 5 files"` |
| 289 | pub(crate) fn build_file_change_summary( |
| 290 | status: &RepositoryStatus, |
| 291 | untracked_paths: &[String], |
| 292 | ) -> String { |
| 293 | let mut added: Vec<String> = Vec::new(); |
| 294 | let mut modified: Vec<String> = Vec::new(); |
| 295 | let mut deleted: Vec<String> = Vec::new(); |
| 296 | |
| 297 | for entry in status.entries() { |
| 298 | let filename = entry |
| 299 | .path() |
| 300 | .file_name() |
| 301 | .map(|n| n.to_string_lossy().to_string()) |
| 302 | .unwrap_or_else(|| entry.path().to_string_lossy().to_string()); |
| 303 | |
| 304 | match entry.status() { |
| 305 | FileStatus::Added => added.push(filename), |
| 306 | FileStatus::Modified => modified.push(filename), |
| 307 | FileStatus::Deleted => deleted.push(filename), |
| 308 | _ => {} |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // Untracked files that will be auto-added count as "Add" |
| 313 | for path in untracked_paths { |
| 314 | let filename = std::path::Path::new(path) |
| 315 | .file_name() |
| 316 | .map(|n| n.to_string_lossy().to_string()) |
| 317 | .unwrap_or_else(|| path.clone()); |
| 318 | added.push(filename); |
| 319 | } |
| 320 | |
| 321 | let mut parts: Vec<String> = Vec::new(); |
| 322 | |
| 323 | if !modified.is_empty() { |
| 324 | parts.push(format_file_group("Modify", &modified)); |
| 325 | } |
| 326 | if !added.is_empty() { |
| 327 | parts.push(format_file_group("Add", &added)); |
| 328 | } |
| 329 | if !deleted.is_empty() { |
| 330 | parts.push(format_file_group("Delete", &deleted)); |
| 331 | } |
| 332 | |
| 333 | parts.join("; ") |
| 334 | } |
| 335 | |
| 336 | /// Format a group of files with a verb prefix. |
| 337 | /// |