Git fix repo selection (#25996)
Release Notes: - git: Fixed a bug where staging/unstaging of hunks could use the wrong git repository if you had many open
This commit is contained in:
parent
495612be2e
commit
2ac952ee6b
3 changed files with 92 additions and 15 deletions
|
@ -24,7 +24,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::Arc;
|
||||
use text::BufferId;
|
||||
use util::{maybe, ResultExt};
|
||||
use worktree::{ProjectEntryId, RepositoryEntry, StatusEntry};
|
||||
use worktree::{ProjectEntryId, RepositoryEntry, StatusEntry, WorkDirectory};
|
||||
|
||||
pub struct GitStore {
|
||||
buffer_store: Entity<BufferStore>,
|
||||
|
@ -691,6 +691,33 @@ impl Repository {
|
|||
self.worktree_id_path_to_repo_path(path.worktree_id, &path.path)
|
||||
}
|
||||
|
||||
// note: callers must verify these come from the same worktree
|
||||
pub fn contains_sub_repo(&self, other: &Entity<Self>, cx: &App) -> bool {
|
||||
let other_work_dir = &other.read(cx).repository_entry.work_directory;
|
||||
match (&self.repository_entry.work_directory, other_work_dir) {
|
||||
(WorkDirectory::InProject { .. }, WorkDirectory::AboveProject { .. }) => false,
|
||||
(WorkDirectory::AboveProject { .. }, WorkDirectory::InProject { .. }) => true,
|
||||
(
|
||||
WorkDirectory::InProject {
|
||||
relative_path: this_path,
|
||||
},
|
||||
WorkDirectory::InProject {
|
||||
relative_path: other_path,
|
||||
},
|
||||
) => other_path.starts_with(this_path),
|
||||
(
|
||||
WorkDirectory::AboveProject {
|
||||
absolute_path: this_path,
|
||||
..
|
||||
},
|
||||
WorkDirectory::AboveProject {
|
||||
absolute_path: other_path,
|
||||
..
|
||||
},
|
||||
) => other_path.starts_with(this_path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn worktree_id_path_to_repo_path(
|
||||
&self,
|
||||
worktree_id: WorktreeId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue