Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git: Fix git info exclude action for worktrees (#63967)

Matei Oprea6b95ac3d33ea
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index 68ff1f73523..aa539e1840c 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -8413,7 +8413,7 @@ impl Repository {
is_dir: bool,
) -> oneshot::Receiver<Result<()>> {
let id = self.id;
- let repository_dir = self.snapshot.repository_dir_abs_path.clone();
+ let repository_dir = self.snapshot.common_dir_abs_path.clone();
let path_display = repo_path.as_ref().display(PathStyle::Unix);
let path = repo_path.as_unix_str().to_owned();
let file_path_str = if is_dir {
diff --git a/crates/remote_server/src/remote_editing_tests.rs b/crates/remote_server/src/remote_editing_tests.rs
index 9d897b58cdb..dc99eb5df6f 100644
--- a/crates/remote_server/src/remote_editing_tests.rs
+++ b/crates/remote_server/src/remote_editing_tests.rs
@@ -3702,6 +3702,92 @@ async fn test_add_path_to_git_info_exclude_in_remote_repository(
);
}
+#[gpui::test]
+async fn test_add_path_to_git_info_exclude_in_remote_linked_worktree(
+ cx: &mut TestAppContext,
+ server_cx: &mut TestAppContext,
+) {
+ let fs = FakeFs::new(server_cx.executor());
+ fs.insert_tree(
+ "/project",
+ json!({
+ ".git": {
+ "HEAD": "ref: refs/heads/main",
+ "config": "[core]\n\tbare = false\n",
+ "info": {
+ "exclude": "existing\n",
+ },
+ "worktrees": {
+ "linked": {
+ "HEAD": "ref: refs/heads/linked",
+ "commondir": "../..",
+ "gitdir": "/worktree/.git",
+ },
+ },
+ },
+ }),
+ )
+ .await;
+ fs.insert_tree(
+ "/worktree",
+ json!({
+ ".git": "gitdir: ../project/.git/worktrees/linked\n",
+ "logs": {
+ "app.log": "",
+ },
+ "tmp.txt": "",
+ }),
+ )
+ .await;
+ let repository_dir = Path::new("/project/.git/worktrees/linked");
+ fs.set_branch_name(repository_dir, Some("linked"));
+ fs.set_head_for_repo(repository_dir, &[], "head-sha");
+
+ let (project, _headless) = init_test(&fs, cx, server_cx).await;
+ project
+ .update(cx, |project, cx| {
+ project.find_or_create_worktree(Path::new("/worktree"), true, cx)
+ })
+ .await
+ .expect("should open remote linked worktree");
+ cx.run_until_parked();
+
+ let repository = project.read_with(cx, |project, cx| {
+ project
+ .active_repository(cx)
+ .expect("remote linked worktree should have an active repository")
+ });
+
+ for (path, is_dir) in [("tmp.txt", false), ("logs", true), ("tmp.txt", false)] {
+ let repo_path = RepoPath::new(path).expect("path should be a valid repo path");
+ cx.update(|cx| {
+ repository.update(cx, |repository, _| {
+ repository.add_path_to_git_info_exclude(&repo_path, is_dir)
+ })
+ })
+ .await
+ .expect("add to info/exclude request should complete")
+ .expect("add to info/exclude should succeed for remote linked worktree");
+ }
+
+ server_cx.run_until_parked();
+ cx.run_until_parked();
+
+ assert_eq!(
+ fs.load(Path::new("/project/.git/info/exclude"))
+ .await
+ .expect("shared info/exclude should be readable"),
+ "existing\ntmp.txt\nlogs/\n"
+ );
+ assert!(
+ fs.metadata(&repository_dir.join("info/exclude"))
+ .await
+ .expect("worktree-specific info/exclude metadata should be readable")
+ .is_none(),
+ "the action should not create a worktree-specific info/exclude"
+ );
+}
+
#[gpui::test]
async fn test_remote_git_diffs(cx: &mut TestAppContext, server_cx: &mut TestAppContext) {
let text_2 = "