Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Log some more information when opening a git repository and when `git show` fails (#51495)
Cole Millerbde0834c6c24
diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rsindex 6c7074d2139..311992d20d9 100644--- a/crates/fs/src/fs.rs+++ b/crates/fs/src/fs.rs@@ -147,7 +147,7 @@ pub trait Fs: Send + Sync {&self,abs_dot_git: &Path,system_git_binary_path: Option<&Path>,- ) -> Option<Arc<dyn GitRepository>>;+ ) -> Result<Arc<dyn GitRepository>>;async fn git_init(&self, abs_work_directory: &Path, fallback_branch_name: String)-> Result<()>;async fn git_clone(&self, repo_url: &str, abs_work_directory: &Path) -> Result<()>;@@ -1149,8 +1149,8 @@ impl Fs for RealFs {&self,dotgit_path: &Path,system_git_binary_path: Option<&Path>,- ) -> Option<Arc<dyn GitRepository>> {- Some(Arc::new(RealGitRepository::new(+ ) -> Result<Arc<dyn GitRepository>> {+ Ok(Arc::new(RealGitRepository::new(dotgit_path,self.bundled_git_binary_path.clone(),system_git_binary_path.map(|path| path.to_path_buf()),@@ -2866,9 +2866,7 @@ impl Fs for FakeFs {&self,abs_dot_git: &Path,_system_git_binary: Option<&Path>,- ) -> Option<Arc<dyn GitRepository>> {- use util::ResultExt as _;-+ ) -> Result<Arc<dyn GitRepository>> {self.with_git_state_and_paths(abs_dot_git,false,@@ -2884,7 +2882,6 @@ impl Fs for FakeFs {}) as _},)- .log_err()}async fn git_init(diff --git a/crates/git/src/commit.rs b/crates/git/src/commit.rsindex a9c9ee633b1..50b62fa506b 100644--- a/crates/git/src/commit.rs+++ b/crates/git/src/commit.rs@@ -91,7 +91,7 @@ async fn get_messages_impl(git: &GitBinary, shas: &[Oid]) -> Result<Vec<String>>anyhow::ensure!(output.status.success(),"'git show' failed with error {:?}",- output.status+ String::from_utf8_lossy(&output.stderr));Ok(String::from_utf8_lossy(&output.stdout).trim()diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rsindex 37523672e38..094e634c7ff 100644--- a/crates/git/src/repository.rs+++ b/crates/git/src/repository.rs@@ -1000,11 +1000,18 @@ impl RealGitRepository {bundled_git_binary_path: Option<PathBuf>,system_git_binary_path: Option<PathBuf>,executor: BackgroundExecutor,- ) -> Option<Self> {- let any_git_binary_path = system_git_binary_path.clone().or(bundled_git_binary_path)?;- let workdir_root = dotgit_path.parent()?;- let repository = git2::Repository::open(workdir_root).log_err()?;- Some(Self {+ ) -> Result<Self> {+ let any_git_binary_path = system_git_binary_path+ .clone()+ .or(bundled_git_binary_path)+ .context("no git binary available")?;+ log::info!(+ "opening git repository at {dotgit_path:?} using git binary {any_git_binary_path:?}"+ );+ let workdir_root = dotgit_path.parent().context(".git has no parent")?;+ let repository =+ git2::Repository::open(workdir_root).context("creating libgit2 repository")?;+ Ok(Self {repository: Arc::new(Mutex::new(repository)),system_git_binary_path,any_git_binary_path,