Skip to content

Commit d732b8b

Browse files
authored
git: Disable commit message generation when commit not possible (#26329)
## Issue: - `Generate Commit Message` will generate a random message if there are no changes. <img width="614" alt="image" src="https://github.com/user-attachments/assets/c16cadac-01af-47c0-a2db-a5bbf62f84bb" /> ## After Fixed: - `Generate Commit Message` will be disabled if commit is not possible <img width="610" alt="image" src="https://github.com/user-attachments/assets/5ea9ca70-6fa3-4144-ab4e-be7a986d5496" /> ## Release Notes: - Fixed: Disable commit message generation when commit is not possible
1 parent 7c3eecc commit d732b8b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

crates/git_ui/src/git_panel.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,10 @@ impl GitPanel {
14531453

14541454
/// Generates a commit message using an LLM.
14551455
pub fn generate_commit_message(&mut self, cx: &mut Context<Self>) {
1456+
if !self.can_commit() {
1457+
return;
1458+
}
1459+
14561460
let model = match current_language_model(cx) {
14571461
Some(value) => value,
14581462
None => return,
@@ -2291,14 +2295,28 @@ impl GitPanel {
22912295
.into_any_element();
22922296
}
22932297

2298+
let can_commit = self.can_commit();
2299+
let editor_focus_handle = self.commit_editor.focus_handle(cx);
22942300
IconButton::new("generate-commit-message", IconName::AiEdit)
22952301
.shape(ui::IconButtonShape::Square)
22962302
.icon_color(Color::Muted)
2297-
.tooltip(Tooltip::for_action_title_in(
2298-
"Generate Commit Message",
2299-
&git::GenerateCommitMessage,
2300-
&self.commit_editor.focus_handle(cx),
2301-
))
2303+
.tooltip(move |window, cx| {
2304+
if can_commit {
2305+
Tooltip::for_action_in(
2306+
"Generate Commit Message",
2307+
&git::GenerateCommitMessage,
2308+
&editor_focus_handle,
2309+
window,
2310+
cx,
2311+
)
2312+
} else {
2313+
Tooltip::simple(
2314+
"You must have either staged changes or tracked files to generate a commit message",
2315+
cx,
2316+
)
2317+
}
2318+
})
2319+
.disabled(!can_commit)
23022320
.on_click(cx.listener(move |this, _event, _window, cx| {
23032321
this.generate_commit_message(cx);
23042322
}))

0 commit comments

Comments
 (0)