File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ package cmd
6
6
import (
7
7
"fmt"
8
8
"os"
9
- "os/exec"
10
9
11
10
"github.com/chand1012/ottodocs/pkg/ai"
12
11
"github.com/chand1012/ottodocs/pkg/config"
@@ -34,16 +33,25 @@ var commitCmd = &cobra.Command{
34
33
os .Exit (1 )
35
34
}
36
35
36
+ dirty , err := git .IsDirty ()
37
+ if err != nil {
38
+ log .Error (err )
39
+ os .Exit (1 )
40
+ }
41
+
42
+ if ! dirty {
43
+ log .Error ("No changes to commit." )
44
+ os .Exit (1 )
45
+ }
46
+
37
47
log .Info ("Generating commit message..." )
38
48
log .Debug ("Getting git diff..." )
39
- c := exec .Command ("git" , "diff" )
40
- diffBytes , err := c .Output ()
49
+ diff , err := git .Diff ()
41
50
if err != nil {
42
51
log .Error (err )
43
52
os .Exit (1 )
44
53
}
45
54
46
- diff := string (diffBytes )
47
55
log .Debug ("Sending diff to ChatGPT..." )
48
56
msg , err := ai .CommitMessage (diff , conventional , conf )
49
57
if err != nil {
Original file line number Diff line number Diff line change
1
+ package git
2
+
3
+ import "strings"
4
+
5
+ func Diff () (string , error ) {
6
+ return git ("diff" )
7
+ }
8
+
9
+ func Status () (string , error ) {
10
+ return git ("status" )
11
+ }
12
+
13
+ func IsDirty () (bool , error ) {
14
+ status , err := Status ()
15
+ if err != nil {
16
+ return false , err
17
+ }
18
+ return ! strings .Contains (status , "nothing to commit, working tree clean" ), nil
19
+ }
You can’t perform that action at this time.
0 commit comments