Make FakeGitRepository behave more like a real git repository (#26961)
This PR reworks the `FakeGitRepository` type that we use for testing git interactions, to make it more realistic. In particular, the `status` method now derives the Git status from the differences between HEAD, the index, and the working copy. This way, if you modify a file in the `FakeFs`, the Git repository's `status` method will reflect that modification. Release Notes: - N/A --------- Co-authored-by: Junkui Zhang <364772080@qq.com>
This commit is contained in:
parent
5f398071b2
commit
74a39c7263
15 changed files with 790 additions and 679 deletions
|
@ -4474,7 +4474,7 @@ mod tests {
|
|||
)
|
||||
.await;
|
||||
|
||||
fs.set_status_for_repo_via_git_operation(
|
||||
fs.set_status_for_repo(
|
||||
Path::new(path!("/root/zed/.git")),
|
||||
&[
|
||||
(
|
||||
|
|
|
@ -1291,16 +1291,13 @@ mod preview {
|
|||
#[cfg(not(target_os = "windows"))]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
|
||||
use collections::HashMap;
|
||||
use db::indoc;
|
||||
use editor::test::editor_test_context::{assert_state_with_diff, EditorTestContext};
|
||||
use git::status::{StatusCode, TrackedStatus};
|
||||
use gpui::TestAppContext;
|
||||
use project::FakeFs;
|
||||
use serde_json::json;
|
||||
use settings::SettingsStore;
|
||||
use std::path::Path;
|
||||
use unindent::Unindent as _;
|
||||
use util::path;
|
||||
|
||||
|
@ -1353,16 +1350,6 @@ mod tests {
|
|||
path!("/project/.git").as_ref(),
|
||||
&[("foo.txt".into(), "foo\n".into())],
|
||||
);
|
||||
fs.with_git_state(path!("/project/.git").as_ref(), true, |state| {
|
||||
state.statuses = HashMap::from_iter([(
|
||||
"foo.txt".into(),
|
||||
TrackedStatus {
|
||||
index_status: StatusCode::Unmodified,
|
||||
worktree_status: StatusCode::Modified,
|
||||
}
|
||||
.into(),
|
||||
)]);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let editor = diff.update(cx, |diff, _| diff.editor.clone());
|
||||
|
@ -1409,33 +1396,13 @@ mod tests {
|
|||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
fs.set_head_for_repo(
|
||||
fs.set_head_and_index_for_repo(
|
||||
path!("/project/.git").as_ref(),
|
||||
&[
|
||||
("bar".into(), "bar\n".into()),
|
||||
("foo".into(), "foo\n".into()),
|
||||
],
|
||||
);
|
||||
fs.with_git_state(path!("/project/.git").as_ref(), true, |state| {
|
||||
state.statuses = HashMap::from_iter([
|
||||
(
|
||||
"bar".into(),
|
||||
TrackedStatus {
|
||||
index_status: StatusCode::Unmodified,
|
||||
worktree_status: StatusCode::Modified,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
(
|
||||
"foo".into(),
|
||||
TrackedStatus {
|
||||
index_status: StatusCode::Unmodified,
|
||||
worktree_status: StatusCode::Modified,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
]);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let editor = cx.update_window_entity(&diff, |diff, window, cx| {
|
||||
|
@ -1515,16 +1482,6 @@ mod tests {
|
|||
path!("/project/.git").as_ref(),
|
||||
&[("foo".into(), "original\n".into())],
|
||||
);
|
||||
fs.with_git_state(path!("/project/.git").as_ref(), true, |state| {
|
||||
state.statuses = HashMap::from_iter([(
|
||||
"foo".into(),
|
||||
TrackedStatus {
|
||||
index_status: StatusCode::Unmodified,
|
||||
worktree_status: StatusCode::Modified,
|
||||
}
|
||||
.into(),
|
||||
)]);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let diff_editor = diff.update(cx, |diff, _| diff.editor.clone());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue