mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
git: Fix both-deleted conflicts being parsed as both-added (#66648)
## Summary Closes #66628 `FileStatus::from_bytes` parsed the `DD` porcelain status ("unmerged, both deleted") as `Added`/`Added`, the same as `AA`. The wrong value went into `StatusEntry::to_proto` and from there to collaborators and the `project_repository_statuses` table. `DD` now parses as `Deleted`/`Deleted`. No code reads these heads to decide behavior: consumers match on `Unmerged { .. }` or pass the value through proto and the database, so nothing depended on the old mapping and there is no UI change. ## Testing Added `test_parse_unmerged_status_codes` in `crates/git/src/status.rs`, which checks all seven unmerged codes (`DD`, `AU`, `UD`, `UA`, `DU`, `AA`, `UU`). Before the fix it fails on `DD`: ``` assertion `left == right` failed: DD left: Unmerged(UnmergedStatus { first_head: Added, second_head: Added }) right: Unmerged(UnmergedStatus { first_head: Deleted, second_head: Deleted }) ``` To confirm that git produces this status, I renamed one file to different names on two branches and merged them. `git status --porcelain=v1 -z` reported `DD original.txt`, along with `AU main.txt` and `UA side.txt`. Run on macOS: - `cargo test -p git` (79 passed) - `cargo test -p project --test integration git_store` (43 passed) - `./script/clippy -p git` - `cargo fmt -p git --check` I did not test this in the running app, since the change has no visible effect there. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [ ] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). (No UI changes) - [x] Tests cover the new or changed behavior. Release Notes: - N/A
This commit is contained in:
@@ -118,8 +118,8 @@ impl FileStatus {
|
||||
}
|
||||
.into(),
|
||||
[b'D', b'D'] => UnmergedStatus {
|
||||
first_head: UnmergedStatusCode::Added,
|
||||
second_head: UnmergedStatusCode::Added,
|
||||
first_head: UnmergedStatusCode::Deleted,
|
||||
second_head: UnmergedStatusCode::Deleted,
|
||||
}
|
||||
.into(),
|
||||
[x, b'U'] => UnmergedStatus {
|
||||
@@ -620,7 +620,9 @@ mod tests {
|
||||
|
||||
use crate::{
|
||||
repository::RepoPath,
|
||||
status::{FileStatus, GitStatus, TreeDiff, TreeDiffStatus},
|
||||
status::{
|
||||
FileStatus, GitStatus, TreeDiff, TreeDiffStatus, UnmergedStatus, UnmergedStatusCode,
|
||||
},
|
||||
};
|
||||
|
||||
use super::{DiffStat, parse_numstat};
|
||||
@@ -716,6 +718,34 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_unmerged_status_codes() {
|
||||
use UnmergedStatusCode::{Added, Deleted, Updated};
|
||||
|
||||
let cases = [
|
||||
("DD", Deleted, Deleted),
|
||||
("AU", Added, Updated),
|
||||
("UD", Updated, Deleted),
|
||||
("UA", Updated, Added),
|
||||
("DU", Deleted, Updated),
|
||||
("AA", Added, Added),
|
||||
("UU", Updated, Updated),
|
||||
];
|
||||
|
||||
for (code, first_head, second_head) in cases {
|
||||
let status: GitStatus = format!("{code} conflicted.txt\0").parse().unwrap();
|
||||
assert_eq!(status.entries.len(), 1, "{code}");
|
||||
assert_eq!(
|
||||
status.entries[0].1,
|
||||
FileStatus::Unmerged(UnmergedStatus {
|
||||
first_head,
|
||||
second_head,
|
||||
}),
|
||||
"{code}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_untracked_entries() {
|
||||
// Regression test for ZED-2XA: git can produce duplicate untracked entries
|
||||
|
||||
Reference in New Issue
Block a user