Closes https://github.com/zed-industries/zed/issues/38690 Closes #37353 ### Background On Windows, paths are normally separated by `\`, unlike mac and linux where they are separated by `/`. When editing code in a project that uses a different path style than your local system (e.g. remoting from Windows to Linux, using WSL, and collaboration between windows and unix users), the correct separator for a path may differ from the "native" separator. Previously, to work around this, Zed converted paths' separators in numerous places. This was applied to both absolute and relative paths, leading to incorrect conversions in some cases. ### Solution Many code paths in Zed use paths that are *relative* to either a worktree root or a git repository. This PR introduces a dedicated type for these paths called `RelPath`, which stores the path in the same way regardless of host platform, and offers `Path`-like manipulation APIs. RelPath supports *displaying* the path using either separator, so that we can display paths in a style that is determined at runtime based on the current project. The representation of absolute paths is left untouched, for now. Absolute paths are different from relative paths because (except in contexts where we know that the path refers to the local filesystem) they should generally be treated as opaque strings. Currently we use a mix of types for these paths (std::path::Path, String, SanitizedPath). Release Notes: - N/A --------- Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Peter Tripp <petertripp@gmail.com> Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com> Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
128 lines
3.7 KiB
Rust
128 lines
3.7 KiB
Rust
use std::path::Path;
|
|
|
|
use call::ActiveCall;
|
|
use git::status::{FileStatus, StatusCode, TrackedStatus};
|
|
use git_ui::project_diff::ProjectDiff;
|
|
use gpui::{TestAppContext, VisualTestContext};
|
|
use project::ProjectPath;
|
|
use serde_json::json;
|
|
use util::{path, rel_path::rel_path};
|
|
use workspace::Workspace;
|
|
|
|
//
|
|
use crate::tests::TestServer;
|
|
|
|
#[gpui::test]
|
|
async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
|
|
let mut server = TestServer::start(cx_a.background_executor.clone()).await;
|
|
let client_a = server.create_client(cx_a, "user_a").await;
|
|
let client_b = server.create_client(cx_b, "user_b").await;
|
|
cx_a.set_name("cx_a");
|
|
cx_b.set_name("cx_b");
|
|
|
|
server
|
|
.create_room(&mut [(&client_a, cx_a), (&client_b, cx_b)])
|
|
.await;
|
|
|
|
client_a
|
|
.fs()
|
|
.insert_tree(
|
|
path!("/a"),
|
|
json!({
|
|
".git": {},
|
|
"changed.txt": "after\n",
|
|
"unchanged.txt": "unchanged\n",
|
|
"created.txt": "created\n",
|
|
"secret.pem": "secret-changed\n",
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
client_a.fs().set_head_and_index_for_repo(
|
|
Path::new(path!("/a/.git")),
|
|
&[
|
|
("changed.txt", "before\n".to_string()),
|
|
("unchanged.txt", "unchanged\n".to_string()),
|
|
("deleted.txt", "deleted\n".to_string()),
|
|
("secret.pem", "shh\n".to_string()),
|
|
],
|
|
);
|
|
let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await;
|
|
let active_call_a = cx_a.read(ActiveCall::global);
|
|
let project_id = active_call_a
|
|
.update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
|
|
.await
|
|
.unwrap();
|
|
|
|
cx_b.update(editor::init);
|
|
cx_b.update(git_ui::init);
|
|
let project_b = client_b.join_remote_project(project_id, cx_b).await;
|
|
let workspace_b = cx_b.add_window(|window, cx| {
|
|
Workspace::new(
|
|
None,
|
|
project_b.clone(),
|
|
client_b.app_state.clone(),
|
|
window,
|
|
cx,
|
|
)
|
|
});
|
|
let cx_b = &mut VisualTestContext::from_window(*workspace_b, cx_b);
|
|
let workspace_b = workspace_b.root(cx_b).unwrap();
|
|
|
|
cx_b.update(|window, cx| {
|
|
window
|
|
.focused(cx)
|
|
.unwrap()
|
|
.dispatch_action(&git_ui::project_diff::Diff, window, cx)
|
|
});
|
|
let diff = workspace_b.update(cx_b, |workspace, cx| {
|
|
workspace.active_item(cx).unwrap().act_as::<ProjectDiff>(cx)
|
|
});
|
|
let diff = diff.unwrap();
|
|
cx_b.run_until_parked();
|
|
|
|
diff.update(cx_b, |diff, cx| {
|
|
assert_eq!(
|
|
diff.excerpt_paths(cx),
|
|
vec!["changed.txt", "deleted.txt", "created.txt"]
|
|
);
|
|
});
|
|
|
|
client_a
|
|
.fs()
|
|
.insert_tree(
|
|
path!("/a"),
|
|
json!({
|
|
".git": {},
|
|
"changed.txt": "before\n",
|
|
"unchanged.txt": "changed\n",
|
|
"created.txt": "created\n",
|
|
"secret.pem": "secret-changed\n",
|
|
}),
|
|
)
|
|
.await;
|
|
cx_b.run_until_parked();
|
|
|
|
project_b.update(cx_b, |project, cx| {
|
|
let project_path = ProjectPath {
|
|
worktree_id,
|
|
path: rel_path("unchanged.txt").into(),
|
|
};
|
|
let status = project.project_path_git_status(&project_path, cx);
|
|
assert_eq!(
|
|
status.unwrap(),
|
|
FileStatus::Tracked(TrackedStatus {
|
|
worktree_status: StatusCode::Modified,
|
|
index_status: StatusCode::Unmodified,
|
|
})
|
|
);
|
|
});
|
|
|
|
diff.update(cx_b, |diff, cx| {
|
|
assert_eq!(
|
|
diff.excerpt_paths(cx),
|
|
vec!["deleted.txt", "unchanged.txt", "created.txt"]
|
|
);
|
|
});
|
|
}
|