Update to suggest commit message based on file staging (#25790)

Currently, you only get a suggested commit message if you have a single
changed file in the repository. After the PR, the suggest happens per
single-staged file.

https://github.com/user-attachments/assets/4cc19fe6-099c-4690-967d-898b8ca7540b

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-02-27 19:19:58 -05:00 committed by GitHub
parent b15aa5e018
commit a5f96909cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1257,40 +1257,39 @@ impl GitPanel {
/// Suggests a commit message based on the changed files and their statuses /// Suggests a commit message based on the changed files and their statuses
pub fn suggest_commit_message(&self) -> Option<String> { pub fn suggest_commit_message(&self) -> Option<String> {
let entries = self if self.total_staged_count() != 1 {
return None;
}
let entry = self
.entries .entries
.iter() .iter()
.filter_map(|entry| { .find(|entry| match entry.status_entry() {
if let GitListEntry::GitStatusEntry(status_entry) = entry { Some(entry) => entry.is_staged.unwrap_or(false),
Some(status_entry) _ => false,
} else { })?;
None
}
})
.collect::<Vec<&GitStatusEntry>>();
if entries.is_empty() { let GitListEntry::GitStatusEntry(git_status_entry) = entry.clone() else {
None return None;
} else if entries.len() == 1 { };
let entry = &entries[0];
let file_name = entry
.repo_path
.file_name()
.unwrap_or_default()
.to_string_lossy();
if entry.status.is_deleted() { let action_text = if git_status_entry.status.is_deleted() {
Some(format!("Delete {}", file_name)) Some("Delete")
} else if entry.status.is_created() { } else if git_status_entry.status.is_created() {
Some(format!("Create {}", file_name)) Some("Create")
} else if entry.status.is_modified() { } else if git_status_entry.status.is_modified() {
Some(format!("Update {}", file_name)) Some("Update")
} else {
None
}
} else { } else {
None None
} };
let file_name = git_status_entry
.repo_path
.file_name()
.unwrap_or_default()
.to_string_lossy();
Some(format!("{} {}", action_text?, file_name))
} }
fn update_editor_placeholder(&mut self, cx: &mut Context<Self>) { fn update_editor_placeholder(&mut self, cx: &mut Context<Self>) {