@@ -27,7 +27,7 @@ import (
2727// CreateCommitMsg launches the interactive flow for reviewing, regenerating,
2828// editing, and accepting AI-generated commit messages in the current repo.
2929// If dryRun is true, it displays the prompt without making an API call.
30- func CreateCommitMsg (dryRun bool ) {
30+ func CreateCommitMsg (dryRun bool , autoCommit bool ) {
3131 // Validate COMMIT_LLM and required API keys
3232 useLLM , err := store .DefaultLLMKey ()
3333 if err != nil {
@@ -208,6 +208,38 @@ interactionLoop:
208208
209209 pterm .Println ()
210210 display .ShowChangesPreview (fileStats )
211+
212+ // Auto-commit if flag is set (cross-platform compatible)
213+ if autoCommit && ! dryRun {
214+ pterm .Println ()
215+ spinner , err := pterm .DefaultSpinner .
216+ WithSequence ("⠋" , "⠙" , "⠹" , "⠸" , "⠼" , "⠴" , "⠦" , "⠧" , "⠇" , "⠏" ).
217+ Start ("Automatically committing with generated message..." )
218+ if err != nil {
219+ pterm .Error .Printf ("Failed to start spinner: %v\n " , err )
220+ return
221+ }
222+
223+ cmd := exec .Command ("git" , "commit" , "-m" , finalMessage )
224+ cmd .Dir = currentDir
225+ // Ensure git command works across all platforms
226+ cmd .Env = os .Environ ()
227+
228+ output , err := cmd .CombinedOutput ()
229+ if err != nil {
230+ spinner .Fail ("Commit failed" )
231+ pterm .Error .Printf ("Failed to commit: %v\n " , err )
232+ if len (output ) > 0 {
233+ pterm .Error .Println (string (output ))
234+ }
235+ return
236+ }
237+
238+ spinner .Success ("Committed successfully!" )
239+ if len (output ) > 0 {
240+ pterm .Info .Println (strings .TrimSpace (string (output )))
241+ }
242+ }
211243}
212244
213245type styleOption struct {
@@ -234,6 +266,7 @@ var (
234266 }
235267 errSelectionCancelled = errors .New ("selection cancelled" )
236268)
269+
237270// resolveOllamaConfig returns the URL and model for Ollama, using environment variables as fallbacks
238271func resolveOllamaConfig (apiKey string ) (url , model string ) {
239272 url = apiKey
@@ -250,7 +283,6 @@ func resolveOllamaConfig(apiKey string) (url, model string) {
250283 return url , model
251284}
252285
253-
254286func generateMessage (provider types.LLMProvider , config * types.Config , changes string , apiKey string , opts * types.GenerationOptions ) (string , error ) {
255287 switch provider {
256288 case types .ProviderGemini :
0 commit comments