From 508b9d3b5da6d76d03cd1f8948c387518d9c448b Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 3 Mar 2025 00:44:46 -0800 Subject: [PATCH] Add an informative tooltip to commit button when unable to commit (#25912) Release Notes: - N/A --- crates/git_ui/src/git_panel.rs | 55 +++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index f6ca388223..dd2082fcc8 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -1858,6 +1858,32 @@ impl GitPanel { } } + pub fn configure_commit_button(&self, cx: &Context) -> (bool, &'static str) { + if self.has_unstaged_conflicts() { + (false, "You must resolve conflicts before committing") + } else if !self.has_staged_changes() && !self.has_tracked_changes() { + ( + false, + "You must have either staged changes or tracked files to commit", + ) + } else if self.pending_commit.is_some() { + (false, "Commit in progress") + } else if self.commit_editor.read(cx).is_empty(cx) { + (false, "No commit message") + } else if !self.has_write_access(cx) { + (false, "You do not have write access to this project") + } else { + ( + true, + if self.has_staged_changes() { + "Commit" + } else { + "Commit Tracked" + }, + ) + } + } + pub fn render_footer( &self, window: &mut Window, @@ -1868,19 +1894,10 @@ impl GitPanel { let panel_editor_style = panel_editor_style(true, window, cx); if let Some(active_repo) = active_repository { - let editor = self.commit_editor.clone(); - let can_commit = self.can_commit() - && self.pending_commit.is_none() - && !editor.read(cx).is_empty(cx) - && self.has_write_access(cx); + let (can_commit, tooltip) = self.configure_commit_button(cx); let enable_coauthors = self.render_co_authors(cx); - let tooltip = if self.has_staged_changes() { - "git commit" - } else { - "git commit --all" - }; let title = if self.has_staged_changes() { "Commit" } else { @@ -1938,13 +1955,17 @@ impl GitPanel { .child( panel_filled_button(title) .tooltip(move |window, cx| { - Tooltip::for_action_in( - tooltip, - &Commit, - &editor_focus_handle, - window, - cx, - ) + if can_commit { + Tooltip::for_action_in( + tooltip, + &Commit, + &editor_focus_handle, + window, + cx, + ) + } else { + Tooltip::simple(tooltip, cx) + } }) .disabled(!can_commit || self.modal_open) .on_click({