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

@ -21,6 +21,7 @@ agent_settings.workspace = true
anyhow.workspace = true
askpass.workspace = true
buffer_diff.workspace = true
call.workspace = true
chrono.workspace = true
collections.workspace = true
command_palette_hooks.workspace = true

View file

@ -148,6 +148,7 @@ impl CommitModal {
}
}
git_panel.set_modal_open(true, cx);
git_panel.load_local_committer(cx);
});
let dock = workspace.dock_at_position(git_panel.position(window, cx));

View file

@ -20,8 +20,9 @@ use editor::{
use futures::StreamExt as _;
use git::blame::ParsedCommitMessage;
use git::repository::{
Branch, CommitDetails, CommitOptions, CommitSummary, DiffType, FetchOptions, PushOptions,
Remote, RemoteCommandOutput, ResetMode, Upstream, UpstreamTracking, UpstreamTrackingStatus,
Branch, CommitDetails, CommitOptions, CommitSummary, DiffType, FetchOptions, GitCommitter,
PushOptions, Remote, RemoteCommandOutput, ResetMode, Upstream, UpstreamTracking,
UpstreamTrackingStatus, get_git_committer,
};
use git::status::StageStatus;
use git::{Amend, ToggleStaged, repository::RepoPath, status::FileStatus};
@ -358,6 +359,8 @@ pub struct GitPanel {
context_menu: Option<(Entity<ContextMenu>, Point<Pixels>, Subscription)>,
modal_open: bool,
show_placeholders: bool,
local_committer: Option<GitCommitter>,
local_committer_task: Option<Task<()>>,
_settings_subscription: Subscription,
}
@ -520,6 +523,8 @@ impl GitPanel {
update_visible_entries_task: Task::ready(()),
width: None,
show_placeholders: false,
local_committer: None,
local_committer_task: None,
context_menu: None,
workspace: workspace.weak_handle(),
modal_open: false,
@ -2250,6 +2255,19 @@ impl GitPanel {
}
}
pub fn load_local_committer(&mut self, cx: &Context<Self>) {
if self.local_committer_task.is_none() {
self.local_committer_task = Some(cx.spawn(async move |this, cx| {
let committer = get_git_committer(cx).await;
this.update(cx, |this, cx| {
this.local_committer = Some(committer);
cx.notify()
})
.ok();
}));
}
}
fn potential_co_authors(&self, cx: &App) -> Vec<(String, String)> {
let mut new_co_authors = Vec::new();
let project = self.project.read(cx);
@ -2272,34 +2290,38 @@ impl GitPanel {
let Some(participant) = room.remote_participant_for_peer_id(*peer_id) else {
continue;
};
if participant.can_write() && participant.user.email.is_some() {
let email = participant.user.email.clone().unwrap();
new_co_authors.push((
participant
.user
.name
.clone()
.unwrap_or_else(|| participant.user.github_login.clone()),
email,
))
if !participant.can_write() {
continue;
}
if let Some(email) = &collaborator.committer_email {
let name = collaborator
.committer_name
.clone()
.or_else(|| participant.user.name.clone())
.unwrap_or_else(|| participant.user.github_login.clone());
new_co_authors.push((name.clone(), email.clone()))
}
}
if !project.is_local() && !project.is_read_only(cx) {
if let Some(user) = room.local_participant_user(cx) {
if let Some(email) = user.email.clone() {
new_co_authors.push((
user.name
.clone()
.unwrap_or_else(|| user.github_login.clone()),
email.clone(),
))
}
if let Some(local_committer) = self.local_committer(room, cx) {
new_co_authors.push(local_committer);
}
}
new_co_authors
}
fn local_committer(&self, room: &call::Room, cx: &App) -> Option<(String, String)> {
let user = room.local_participant_user(cx)?;
let committer = self.local_committer.as_ref()?;
let email = committer.email.clone()?;
let name = committer
.name
.clone()
.or_else(|| user.name.clone())
.unwrap_or_else(|| user.github_login.clone());
Some((name, email))
}
fn toggle_fill_co_authors(
&mut self,
_: &ToggleFillCoAuthors,
@ -4244,8 +4266,9 @@ impl Render for GitPanel {
let has_write_access = self.has_write_access(cx);
let has_co_authors = room.map_or(false, |room| {
room.read(cx)
.remote_participants()
self.load_local_committer(cx);
let room = room.read(cx);
room.remote_participants()
.values()
.any(|remote_participant| remote_participant.can_write())
});