Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git: Fix panic on duplicate status entries in git status parsing (#49191)

morgankreyca0fffb927b9
diff --git a/crates/git/src/status.rs b/crates/git/src/status.rs
index 2cf7cc7c181..be8b0a3a588 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() +