Refactor Repository::status_for_path
to return FileStatus
instead of StatusEntry
This commit is contained in:
parent
b696a32518
commit
b40794d413
5 changed files with 24 additions and 40 deletions
|
@ -3072,12 +3072,7 @@ async fn test_git_status_sync(
|
|||
.collect::<Vec<_>>();
|
||||
assert_eq!(repos.len(), 1);
|
||||
let repo = repos.into_iter().next().unwrap();
|
||||
assert_eq!(
|
||||
repo.read(cx)
|
||||
.status_for_path(&file.into())
|
||||
.map(|entry| entry.status),
|
||||
status
|
||||
);
|
||||
assert_eq!(repo.read(cx).status_for_path(&file.into()), status);
|
||||
}
|
||||
|
||||
project_local.read_with(cx_a, |project, cx| {
|
||||
|
|
|
@ -685,7 +685,7 @@ impl Item for Editor {
|
|||
.git_store()
|
||||
.read(cx)
|
||||
.repository_and_path_for_buffer_id(buffer_id, cx)?;
|
||||
let status = repo.read(cx).status_for_path(&repo_path)?.status;
|
||||
let status = repo.read(cx).status_for_path(&repo_path)?;
|
||||
|
||||
Some(entry_git_aware_label_color(
|
||||
status.summary(),
|
||||
|
|
|
@ -2693,9 +2693,7 @@ impl OutlinePanel {
|
|||
let status = git_store
|
||||
.read(cx)
|
||||
.repository_and_path_for_buffer_id(buffer_id, cx)
|
||||
.and_then(|(repo, path)| {
|
||||
Some(repo.read(cx).status_for_path(&path)?.status)
|
||||
});
|
||||
.and_then(|(repo, path)| Some(repo.read(cx).status_for_path(&path)?));
|
||||
buffer_excerpts
|
||||
.entry(buffer_id)
|
||||
.or_insert_with(|| {
|
||||
|
|
|
@ -809,7 +809,7 @@ impl GitStore {
|
|||
cx: &App,
|
||||
) -> Option<FileStatus> {
|
||||
let (repo, repo_path) = self.repository_and_path_for_project_path(project_path, cx)?;
|
||||
Some(repo.read(cx).status_for_path(&repo_path)?.status)
|
||||
Some(repo.read(cx).status_for_path(&repo_path)?)
|
||||
}
|
||||
|
||||
pub fn checkpoint(&self, cx: &mut App) -> Task<Result<GitStoreCheckpoint>> {
|
||||
|
@ -1391,8 +1391,7 @@ impl GitStore {
|
|||
|
||||
pub fn status_for_buffer_id(&self, buffer_id: BufferId, cx: &App) -> Option<FileStatus> {
|
||||
let (repo, path) = self.repository_and_path_for_buffer_id(buffer_id, cx)?;
|
||||
let status = repo.read(cx).snapshot.status_for_path(&path)?;
|
||||
Some(status.status)
|
||||
repo.read(cx).snapshot.status_for_path(&path)
|
||||
}
|
||||
|
||||
pub fn repository_and_path_for_buffer_id(
|
||||
|
@ -2844,10 +2843,10 @@ impl RepositorySnapshot {
|
|||
self.statuses_by_path.summary().item_summary
|
||||
}
|
||||
|
||||
pub fn status_for_path(&self, path: &RepoPath) -> Option<StatusEntry> {
|
||||
pub fn status_for_path(&self, path: &RepoPath) -> Option<FileStatus> {
|
||||
self.statuses_by_path
|
||||
.get(&PathKey(path.0.clone()), &())
|
||||
.cloned()
|
||||
.map(|entry| entry.status.clone())
|
||||
}
|
||||
|
||||
pub fn abs_path_to_repo_path(&self, abs_path: &Path) -> Option<RepoPath> {
|
||||
|
@ -2874,7 +2873,7 @@ impl RepositorySnapshot {
|
|||
self.merge.conflicted_paths.contains(repo_path);
|
||||
let has_conflict_currently = self
|
||||
.status_for_path(repo_path)
|
||||
.is_some_and(|entry| entry.status.is_conflicted());
|
||||
.is_some_and(|status| status.is_conflicted());
|
||||
had_conflict_on_last_merge_head_change || has_conflict_currently
|
||||
}
|
||||
|
||||
|
|
|
@ -8246,7 +8246,7 @@ async fn test_repository_subfolder_git_status(
|
|||
|
||||
assert_eq!(repository.status_for_path(&C_TXT.into()), None);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&E_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&E_TXT.into()).unwrap(),
|
||||
FileStatus::Untracked
|
||||
);
|
||||
});
|
||||
|
@ -8459,15 +8459,11 @@ async fn test_rename_work_directory(cx: &mut gpui::TestAppContext) {
|
|||
root_path.join("projects/project1").as_path()
|
||||
);
|
||||
assert_eq!(
|
||||
repository
|
||||
.status_for_path(&"a".into())
|
||||
.map(|entry| entry.status),
|
||||
repository.status_for_path(&"a".into()),
|
||||
Some(StatusCode::Modified.worktree()),
|
||||
);
|
||||
assert_eq!(
|
||||
repository
|
||||
.status_for_path(&"b".into())
|
||||
.map(|entry| entry.status),
|
||||
repository.status_for_path(&"b".into()),
|
||||
Some(FileStatus::Untracked),
|
||||
);
|
||||
});
|
||||
|
@ -8485,11 +8481,11 @@ async fn test_rename_work_directory(cx: &mut gpui::TestAppContext) {
|
|||
root_path.join("projects/project2").as_path()
|
||||
);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&"a".into()).unwrap().status,
|
||||
repository.status_for_path(&"a".into()).unwrap(),
|
||||
StatusCode::Modified.worktree(),
|
||||
);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&"b".into()).unwrap().status,
|
||||
repository.status_for_path(&"b".into()).unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
});
|
||||
|
@ -8562,11 +8558,11 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
repository.status_for_path(&B_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&B_TXT.into()).unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&F_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&F_TXT.into()).unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
});
|
||||
|
@ -8582,7 +8578,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
// The worktree detects that the file's git status has changed.
|
||||
repository.read_with(cx, |repository, _| {
|
||||
assert_eq!(
|
||||
repository.status_for_path(&A_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&A_TXT.into()).unwrap(),
|
||||
StatusCode::Modified.worktree(),
|
||||
);
|
||||
});
|
||||
|
@ -8600,7 +8596,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
// The worktree detects that the files' git status have changed.
|
||||
repository.read_with(cx, |repository, _cx| {
|
||||
assert_eq!(
|
||||
repository.status_for_path(&F_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&F_TXT.into()).unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
assert_eq!(repository.status_for_path(&B_TXT.into()), None);
|
||||
|
@ -8623,11 +8619,11 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
repository.read_with(cx, |repository, _cx| {
|
||||
assert_eq!(repository.status_for_path(&A_TXT.into()), None);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&B_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&B_TXT.into()).unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
assert_eq!(
|
||||
repository.status_for_path(&E_TXT.into()).unwrap().status,
|
||||
repository.status_for_path(&E_TXT.into()).unwrap(),
|
||||
StatusCode::Modified.worktree(),
|
||||
);
|
||||
});
|
||||
|
@ -8666,8 +8662,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
assert_eq!(
|
||||
repository
|
||||
.status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into())
|
||||
.unwrap()
|
||||
.status,
|
||||
.unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
});
|
||||
|
@ -8690,8 +8685,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
|
|||
assert_eq!(
|
||||
repository
|
||||
.status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into())
|
||||
.unwrap()
|
||||
.status,
|
||||
.unwrap(),
|
||||
FileStatus::Untracked,
|
||||
);
|
||||
});
|
||||
|
@ -9000,7 +8994,7 @@ async fn test_git_worktrees_and_submodules(cx: &mut gpui::TestAppContext) {
|
|||
barrier.await.unwrap();
|
||||
worktree_repo.update(cx, |repo, _| {
|
||||
pretty_assertions::assert_eq!(
|
||||
repo.status_for_path(&"src/b.txt".into()).unwrap().status,
|
||||
repo.status_for_path(&"src/b.txt".into()).unwrap(),
|
||||
StatusCode::Modified.worktree(),
|
||||
);
|
||||
});
|
||||
|
@ -9039,7 +9033,7 @@ async fn test_git_worktrees_and_submodules(cx: &mut gpui::TestAppContext) {
|
|||
barrier.await.unwrap();
|
||||
submodule_repo.update(cx, |repo, _| {
|
||||
pretty_assertions::assert_eq!(
|
||||
repo.status_for_path(&"c.txt".into()).unwrap().status,
|
||||
repo.status_for_path(&"c.txt".into()).unwrap(),
|
||||
StatusCode::Modified.worktree(),
|
||||
);
|
||||
});
|
||||
|
@ -9300,9 +9294,7 @@ fn assert_entry_git_state(
|
|||
let entry = tree
|
||||
.entry_for_path(path)
|
||||
.unwrap_or_else(|| panic!("entry {path} not found"));
|
||||
let status = repository
|
||||
.status_for_path(&path.into())
|
||||
.map(|entry| entry.status);
|
||||
let status = repository.status_for_path(&path.into()).map(|entry| entry);
|
||||
let expected = index_status.map(|index_status| {
|
||||
TrackedStatus {
|
||||
index_status,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue