Worktree paths in git panel, take 2 (#26047)

Modified version of #25950. We still use worktree paths, but repo paths
with a status that lie outside the worktree are not excluded; instead,
we relativize them by adding `..`. This makes the list in the git panel
match what you'd get from running `git status` (with the repo's worktree
root as the working directory).

- [x] Implement + test new unrelativization logic
- [x] ~~When collecting repositories, dedup by .git abs path, so
worktrees can share a repo at the project level~~ dedup repos at the
repository selector layer, with repos coming from larger worktrees being
preferred
- [x] Open single-file worktree with diff when activating a path not in
the worktree

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-03-06 17:55:28 -05:00 committed by GitHub
parent 330e799293
commit 1763dd714b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 724 additions and 184 deletions

View file

@ -56,6 +56,9 @@ pub struct Repository {
git_store: WeakEntity<GitStore>,
pub worktree_id: WorktreeId,
pub repository_entry: RepositoryEntry,
pub dot_git_abs_path: PathBuf,
pub worktree_abs_path: Arc<Path>,
pub is_from_single_file_worktree: bool,
pub git_repo: GitRepo,
pub merge_message: Option<String>,
job_sender: mpsc::UnboundedSender<GitJob>,
@ -227,6 +230,9 @@ impl GitStore {
askpass_delegates: Default::default(),
latest_askpass_id: 0,
repository_entry: repo.clone(),
dot_git_abs_path: worktree.dot_git_abs_path(&repo.work_directory),
worktree_abs_path: worktree.abs_path(),
is_from_single_file_worktree: worktree.is_single_file(),
git_repo,
job_sender: self.update_sender.clone(),
merge_message,
@ -979,7 +985,7 @@ impl Repository {
}
pub fn repo_path_to_project_path(&self, path: &RepoPath) -> Option<ProjectPath> {
let path = self.repository_entry.unrelativize(path)?;
let path = self.repository_entry.try_unrelativize(path)?;
Some((self.worktree_id, path).into())
}
@ -1218,7 +1224,7 @@ impl Repository {
if let Some(buffer_store) = self.buffer_store(cx) {
buffer_store.update(cx, |buffer_store, cx| {
for path in &entries {
let Some(path) = self.repository_entry.unrelativize(path) else {
let Some(path) = self.repository_entry.try_unrelativize(path) else {
continue;
};
let project_path = (self.worktree_id, path).into();
@ -1287,7 +1293,7 @@ impl Repository {
if let Some(buffer_store) = self.buffer_store(cx) {
buffer_store.update(cx, |buffer_store, cx| {
for path in &entries {
let Some(path) = self.repository_entry.unrelativize(path) else {
let Some(path) = self.repository_entry.try_unrelativize(path) else {
continue;
};
let project_path = (self.worktree_id, path).into();