Skip to content

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

Merged
cole-miller merged 1 commit intomainfrom
fix/zed-2xa-duplicate-untracked-status
Feb 24, 2026
Merged

git: Fix panic on duplicate status entries in git status parsing#49191
cole-miller merged 1 commit intomainfrom
fix/zed-2xa-duplicate-untracked-status

Conversation

@morgankrey
Copy link
Contributor

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_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

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 14, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 14, 2026
@morgankrey morgankrey force-pushed the fix/zed-2xa-duplicate-untracked-status branch from 755df90 to 6f0137a Compare February 14, 2026 21:03
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>
@morgankrey morgankrey force-pushed the fix/zed-2xa-duplicate-untracked-status branch from 6f0137a to a81234a Compare February 14, 2026 21:06
@morgankrey
Copy link
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!

@cole-miller cole-miller merged commit ca0fffb into main Feb 24, 2026
27 checks passed
@cole-miller cole-miller deleted the fix/zed-2xa-duplicate-untracked-status branch February 24, 2026 20:16
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants