Use git config --global user.email for email address in automatic Co-authored-by (#32624)

Release Notes:

- Automatic population of `Co-authored-by` now uses `git config --global
user.email`

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Michael Sloan 2025-06-12 13:39:08 -06:00 committed by GitHub
parent e56a027bea
commit 7d708c14e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 188 additions and 69 deletions

View file

@ -26,8 +26,8 @@ use std::{
};
use sum_tree::MapSeekTarget;
use thiserror::Error;
use util::ResultExt;
use util::command::{new_smol_command, new_std_command};
use util::{ResultExt, paths};
use uuid::Uuid;
pub use askpass::{AskPassDelegate, AskPassResult, AskPassSession};
@ -508,6 +508,50 @@ pub struct GitRepositoryCheckpoint {
pub commit_sha: Oid,
}
#[derive(Debug)]
pub struct GitCommitter {
pub name: Option<String>,
pub email: Option<String>,
}
pub async fn get_git_committer(cx: &AsyncApp) -> GitCommitter {
if cfg!(any(feature = "test-support", test)) {
return GitCommitter {
name: None,
email: None,
};
}
let git_binary_path =
if cfg!(target_os = "macos") && option_env!("ZED_BUNDLE").as_deref() == Some("true") {
cx.update(|cx| {
cx.path_for_auxiliary_executable("git")
.context("could not find git binary path")
.log_err()
})
.ok()
.flatten()
} else {
None
};
let git = GitBinary::new(
git_binary_path.unwrap_or(PathBuf::from("git")),
paths::home_dir().clone(),
cx.background_executor().clone(),
);
cx.background_spawn(async move {
let name = git.run(["config", "--global", "user.name"]).await.log_err();
let email = git
.run(["config", "--global", "user.email"])
.await
.log_err();
GitCommitter { name, email }
})
.await
}
impl GitRepository for RealGitRepository {
fn reload_index(&self) {
if let Ok(mut index) = self.repository.lock().index() {