1616 conventionalCommits bool
1717 noConventionalCommits bool
1818 commitsWithDescriptions bool
19+ amendCommit bool
1920)
2021
2122// Cmd represents the commit command
@@ -33,6 +34,7 @@ func init() {
3334 Cmd .Flags ().BoolVar (& conventionalCommits , "conventional" , false , "Use conventional commit format (type(scope): description)" )
3435 Cmd .Flags ().BoolVar (& noConventionalCommits , "no-conventional" , false , "Don't use conventional commit format" )
3536 Cmd .Flags ().BoolVar (& commitsWithDescriptions , "with-descriptions" , false , "Generate commit messages with detailed descriptions" )
37+ Cmd .Flags ().BoolVarP (& amendCommit , "amend" , "a" , false , "Amend the previous commit instead of creating a new one" )
3638}
3739
3840func executeCommit () {
@@ -43,8 +45,12 @@ func executeCommit() {
4345
4446 // Check if there are staged changes
4547 if ! git .HasStagedChanges () {
46- logger .Error ("No staged changes found. Please stage your changes with 'git add' first." )
47- os .Exit (1 )
48+ if amendCommit {
49+ logger .PrintMessage ("No staged changes found. Will amend the previous commit message only." )
50+ } else {
51+ logger .Error ("No staged changes found. Please stage your changes with 'git add' first." )
52+ os .Exit (1 )
53+ }
4854 }
4955
5056 // If the --with-descriptions flag wasn't explicitly set, check git config
@@ -68,10 +74,18 @@ func executeCommit() {
6874 // Determine whether to use conventional commits format
6975 useConventionalCommits := shouldUseConventionalCommits ()
7076
71- // Generate commit message based on staged changes and history
72- logger .PrintMessage ("Generating commit message with LLM..." )
77+ // Generate commit message based on staged changes and history - with spinner
78+ spinner , err := ui .ShowSpinner ("Generating commit message with LLM..." )
79+ if err != nil {
80+ logger .Error ("Failed to start spinner: %v" , err )
81+ }
82+
7383 message := llm .GenerateCommitMessage (cfg , diff , recentCommits , useConventionalCommits , commitsWithDescriptions )
7484
85+ if spinner != nil {
86+ spinner .Success ("Commit message generated!" )
87+ }
88+
7589 // If auto-approve flag is not set, ask user to confirm or edit
7690 var proceed bool
7791 if ! autoApprove {
@@ -92,12 +106,16 @@ func executeCommit() {
92106 }
93107
94108 // Create the commit with the message
95- err = git .CreateCommit (message )
109+ err = git .CreateCommit (message , amendCommit )
96110 if err != nil {
97111 logger .Fatal ("Failed to create commit: %v" , err )
98112 }
99113
100- logger .PrintMessage ("Commit created successfully!" )
114+ if amendCommit {
115+ logger .PrintMessage ("Commit amended successfully!" )
116+ } else {
117+ logger .PrintMessage ("Commit created successfully!" )
118+ }
101119}
102120
103121// shouldUseConventionalCommits determines whether to use conventional commit format
0 commit comments