From a81234ae1323b9984c32943dc71f9558a46465d1 Mon Sep 17 00:00:00 2001 From: morgankrey Date: Sat, 14 Feb 2026 14:48:50 -0600 Subject: [PATCH] git: Fix panic on duplicate status entries in git status parsing The `dedup_by` closure in `GitStatus::from_str` panicked when git produced duplicate status entries for the same path (e.g., two `??` untracked entries). This can happen in practice and was reported as ZED-2XA (22 occurrences, 3 users). - Identical duplicate statuses are now silently deduplicated - Other unexpected duplicates log a warning instead of crashing - Added regression test Fixes ZED-2XA Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- crates/git/src/status.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/git/src/status.rs b/crates/git/src/status.rs index 2cf7cc7c181062..be8b0a3a588b40 100644 --- a/crates/git/src/status.rs +++ b/crates/git/src/status.rs @@ -475,7 +475,12 @@ impl FromStr for GitStatus { } .into(); } - _ => panic!("Unexpected duplicated status entries: {a_status:?} and {b_status:?}"), + (x, y) if x == y => {} + _ => { + log::warn!( + "Unexpected duplicated status entries: {a_status:?} and {b_status:?}" + ); + } } true }); @@ -580,9 +585,19 @@ mod tests { use crate::{ repository::RepoPath, - status::{TreeDiff, TreeDiffStatus}, + status::{FileStatus, GitStatus, TreeDiff, TreeDiffStatus}, }; + #[test] + fn test_duplicate_untracked_entries() { + // Regression test for ZED-2XA: git can produce duplicate untracked entries + // for the same path. This should deduplicate them instead of panicking. + let input = "?? file.txt\0?? file.txt"; + let status: GitStatus = input.parse().unwrap(); + assert_eq!(status.entries.len(), 1); + assert_eq!(status.entries[0].1, FileStatus::Untracked); + } + #[test] fn test_tree_diff_parsing() { let input = ":000000 100644 0000000000000000000000000000000000000000 0062c311b8727c3a2e3cd7a41bc9904feacf8f98 A\x00.zed/settings.json\x00".to_owned() +