Skip to content

Commit 73008d7

Browse files
author
R0n0066
committed
update(utils): Charsh faster if stage is empty
1 parent 70ce056 commit 73008d7

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

cmd/utils.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
)
3838

3939
var w *git.Worktree
40+
var hasStagingFiles bool
4041

4142
func checkErr(err error) {
4243
if err != nil {
@@ -108,35 +109,21 @@ func promptList() {
108109
}
109110

110111
func commit(message string) (err error) {
111-
s, err := w.Status()
112+
username, err := gitconfig.Username()
113+
email, err := gitconfig.Email()
114+
fmt.Println(Gray("Changes added, Preparing commit..."))
115+
116+
_, err = w.Commit(message, &git.CommitOptions{
117+
Author: &object.Signature{
118+
Name: username,
119+
Email: email,
120+
When: time.Now(),
121+
},
122+
})
112123
checkErr(err)
113-
114-
hasStagingFiles := false
115-
for _, status := range s {
116-
if status.Staging != 32 && status.Staging != 63 {
117-
hasStagingFiles = true
118-
}
119-
}
120-
121-
if hasStagingFiles {
122-
username, err := gitconfig.Username()
123-
email, err := gitconfig.Email()
124-
fmt.Println(Gray("Changes added, Preparing commit..."))
125-
126-
_, err = w.Commit(message, &git.CommitOptions{
127-
Author: &object.Signature{
128-
Name: username,
129-
Email: email,
130-
When: time.Now(),
131-
},
132-
})
133-
checkErr(err)
134-
lastCommit := "Last commit: " + message
135-
fmt.Println(Gray(lastCommit))
136-
fmt.Println(Green("Done"))
137-
} else {
138-
checkErr(errors.New("No changes added to commit"))
139-
}
124+
lastCommit := "Last commit: " + message
125+
fmt.Println(Gray(lastCommit))
126+
fmt.Println(Green("Done"))
140127

141128
return
142129
}
@@ -152,6 +139,19 @@ func init() {
152139
go (func() {
153140
w, err = r.Worktree()
154141
checkErr(err)
155-
_ = w
142+
143+
s, err := w.Status()
144+
checkErr(err)
145+
146+
hasStagingFiles = false
147+
for _, status := range s {
148+
if status.Staging != 32 && status.Staging != 63 {
149+
hasStagingFiles = true
150+
}
151+
}
152+
153+
if !hasStagingFiles {
154+
checkErr(errors.New("No changes added to commit"))
155+
}
156156
})()
157157
}

0 commit comments

Comments
 (0)