git: Fix panic on duplicate status entries in git status parsing#49191
Merged
cole-miller merged 1 commit intomainfrom Feb 24, 2026
Merged
git: Fix panic on duplicate status entries in git status parsing#49191cole-miller merged 1 commit intomainfrom
cole-miller merged 1 commit intomainfrom
Conversation
755df90 to
6f0137a
Compare
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>
6f0137a to
a81234a
Compare
Contributor
Author
|
@cole-miller testing our sentry fixit bot on a very minor crash reported in sentry, holler if this makes sense and is good code! |
tahayvr
pushed a commit
to tahayvr/zed
that referenced
this pull request
Mar 4, 2026
…-industries#49191) ## Summary Fixes **ZED-2XA** — "Unexpected duplicated status entries: Untracked and Untracked" crash. **Impact:** 22 occurrences, 3 users affected (Sentry). The panic was introduced in zed-industries#23483 (2025-01-22) which added the `dedup_by` logic for handling deleted-in-index + untracked file combinations. No related GitHub issues were found filed against this crash. ## Root Cause `GitStatus::from_str` sorts entries by path and then calls `dedup_by` to merge duplicate entries. The only handled case was `(INDEX_DELETED, Untracked)` — all other duplicates hit a catch-all `panic!`. In practice, git can produce duplicate `??` (untracked) entries for the same path, which triggered this crash. ## Fix - Identical duplicate statuses (e.g., `Untracked, Untracked`) are now silently deduplicated (keep one) - Other unexpected duplicate combinations log a warning instead of crashing - Added a regression test that parses `"?? file.txt\0?? file.txt"` and verifies it produces a single entry ## Verification - Reproduction test passes: `cargo test -p git -- test_duplicate_untracked_entries` - Full crate tests pass: `cargo test -p git` (20/20) - Clippy clean: `./script/clippy` Release Notes: - Fixed a crash when git produces duplicate status entries for the same file path Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes ZED-2XA — "Unexpected duplicated status entries: Untracked and Untracked" crash.
Impact: 22 occurrences, 3 users affected (Sentry). The panic was introduced in #23483 (2025-01-22) which added the
dedup_bylogic for handling deleted-in-index + untracked file combinations.No related GitHub issues were found filed against this crash.
Root Cause
GitStatus::from_strsorts entries by path and then callsdedup_byto merge duplicate entries. The only handled case was(INDEX_DELETED, Untracked)— all other duplicates hit a catch-allpanic!. In practice, git can produce duplicate??(untracked) entries for the same path, which triggered this crash.Fix
Untracked, Untracked) are now silently deduplicated (keep one)"?? file.txt\0?? file.txt"and verifies it produces a single entryVerification
cargo test -p git -- test_duplicate_untracked_entriescargo test -p git(20/20)./script/clippyRelease Notes: