@@ -1453,6 +1453,10 @@ impl GitPanel {
1453
1453
1454
1454
/// Generates a commit message using an LLM.
1455
1455
pub fn generate_commit_message ( & mut self , cx : & mut Context < Self > ) {
1456
+ if !self . can_commit ( ) {
1457
+ return ;
1458
+ }
1459
+
1456
1460
let model = match current_language_model ( cx) {
1457
1461
Some ( value) => value,
1458
1462
None => return ,
@@ -2291,14 +2295,28 @@ impl GitPanel {
2291
2295
. into_any_element ( ) ;
2292
2296
}
2293
2297
2298
+ let can_commit = self . can_commit ( ) ;
2299
+ let editor_focus_handle = self . commit_editor . focus_handle ( cx) ;
2294
2300
IconButton :: new ( "generate-commit-message" , IconName :: AiEdit )
2295
2301
. shape ( ui:: IconButtonShape :: Square )
2296
2302
. 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)
2302
2320
. on_click ( cx. listener ( move |this, _event, _window, cx| {
2303
2321
this. generate_commit_message ( cx) ;
2304
2322
} ) )
0 commit comments