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.

Respect .git/info/exclude in secondary worktrees (#51536)

Fanteria99c67b8d152b
diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs
index c34f358bc84..dc1f208fac7 100644
--- a/crates/worktree/src/worktree.rs
+++ b/crates/worktree/src/worktree.rs
@@ -5568,7 +5568,9 @@ async fn discover_ancestor_git_repo(
};
}
- let repo_exclude_abs_path = ancestor_dot_git.join(REPO_EXCLUDE);
+ let dot_git_path: Arc<Path> = ancestor_dot_git.into();
+ let (_, common_dir_abs_path) = discover_git_paths(&dot_git_path, fs.as_ref()).await;
+ let repo_exclude_abs_path = common_dir_abs_path.join(REPO_EXCLUDE);
if let Ok(repo_exclude) = build_gitignore(&repo_exclude_abs_path, fs.as_ref()).await {
exclude = Some(Arc::new(repo_exclude));
}
diff --git a/crates/worktree/tests/integration/main.rs b/crates/worktree/tests/integration/main.rs
index 2fedafc591f..7ea63f878cc 100644
--- a/crates/worktree/tests/integration/main.rs
+++ b/crates/worktree/tests/integration/main.rs
@@ -2844,6 +2844,76 @@ async fn test_global_gitignore(executor: BackgroundExecutor, cx: &mut TestAppCon
});
}
+#[gpui::test]
+async fn test_repo_exclude_in_worktree(executor: BackgroundExecutor, cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(executor);
+
+ fs.insert_tree(
+ path!("/repo"),
+ json!({
+ ".git": {
+ "info": {
+ "exclude": ".env.*"
+ },
+ "worktrees": {
+ "my-worktree": {
+ "commondir": "../.."
+ }
+ }
+ }
+ }),
+ )
+ .await;
+
+ fs.insert_tree(
+ path!("/worktree"),
+ json!({
+ // .git is pointing to the repo
+ ".git": "gitdir: /repo/.git/worktrees/my-worktree",
+ ".env.local": "secret=1234",
+ "not-ignored.txt": "",
+ }),
+ )
+ .await;
+
+ let worktree = Worktree::local(
+ path!("/worktree").as_ref(),
+ true,
+ fs.clone(),
+ Default::default(),
+ true,
+ WorktreeId::from_proto(0),
+ &mut cx.to_async(),
+ )
+ .await
+ .unwrap();
+
+ worktree
+ .update(cx, |worktree, _| {
+ worktree.as_local().unwrap().scan_complete()
+ })
+ .await;
+ cx.run_until_parked();
+
+ // .env.local should be ignored via info/exclude from the repo's exclude
+ worktree.update(cx, |worktree, _cx| {
+ let expected_excluded_paths = [];
+ let expected_ignored_paths = [".env.local"];
+ let expected_tracked_paths = ["not-ignored.txt"];
+ let expected_included_paths = [];
+
+ check_worktree_entries(
+ worktree,
+ &expected_excluded_paths,
+ &expected_ignored_paths,
+ &expected_tracked_paths,
+ &expected_included_paths,
+ );
+ });
+}
+
#[gpui::test]
async fn test_repo_exclude(executor: BackgroundExecutor, cx: &mut TestAppContext) {
init_test(cx);