diff --git a/crates/fs/src/fake_git_repo.rs b/crates/fs/src/fake_git_repo.rs index 30643bfd0b5b710e627e827294fc4076c177c48c..751796fb83164b78dc5d6789f0ae7870eff16ce1 100644 --- a/crates/fs/src/fake_git_repo.rs +++ b/crates/fs/src/fake_git_repo.rs @@ -1306,6 +1306,10 @@ impl GitRepository for FakeGitRepository { }) } + fn repair_worktrees(&self) -> BoxFuture<'_, Result<()>> { + async { Ok(()) }.boxed() + } + fn set_trusted(&self, trusted: bool) { self.is_trusted .store(trusted, std::sync::atomic::Ordering::Release); diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 3edc2aa60d634d33ffa1946324385102c22b7f35..c42d2e28cf041e40404c1b8276ddcf5d10ca5f01 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -921,6 +921,8 @@ pub trait GitRepository: Send + Sync { fn delete_ref(&self, ref_name: String) -> BoxFuture<'_, Result<()>>; + fn repair_worktrees(&self) -> BoxFuture<'_, Result<()>>; + fn set_trusted(&self, trusted: bool); fn is_trusted(&self) -> bool; } @@ -2208,6 +2210,17 @@ impl GitRepository for RealGitRepository { .boxed() } + fn repair_worktrees(&self) -> BoxFuture<'_, Result<()>> { + let git_binary = self.git_binary(); + self.executor + .spawn(async move { + let args: Vec = vec!["worktree".into(), "repair".into()]; + git_binary?.run(&args).await?; + Ok(()) + }) + .boxed() + } + fn push( &self, branch_name: String, diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index 4ffda4971e1f9c25a6ef448f3631846ddb421e3a..64f8a71277dd44f64f56bf9c50f8bef746c6f808 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -6118,6 +6118,33 @@ impl Repository { }) } + pub fn resolve_commit(&mut self, sha: String) -> oneshot::Receiver> { + self.send_job(None, move |repo, _cx| async move { + match repo { + RepositoryState::Local(LocalRepositoryState { backend, .. }) => { + let results = backend.revparse_batch(vec![sha]).await?; + Ok(results.into_iter().next().flatten().is_some()) + } + RepositoryState::Remote(_) => { + anyhow::bail!("resolve_commit is not supported for remote repositories") + } + } + }) + } + + pub fn repair_worktrees(&mut self) -> oneshot::Receiver> { + self.send_job(None, move |repo, _cx| async move { + match repo { + RepositoryState::Local(LocalRepositoryState { backend, .. }) => { + backend.repair_worktrees().await + } + RepositoryState::Remote(_) => { + anyhow::bail!("repair_worktrees is not supported for remote repositories") + } + } + }) + } + pub fn remove_worktree(&mut self, path: PathBuf, force: bool) -> oneshot::Receiver> { let id = self.id; self.send_job(