File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,10 @@ func hasStagedFiles() error {
2323 var buf bytes.Buffer
2424 err := gitCommand (& buf , []string {"diff" , "--cached" , "--name-only" })
2525 if err != nil {
26- return errors .New (buf .String ())
26+ return err
27+ }
28+ if strings .TrimSpace (buf .String ()) == "" {
29+ return errors .New ("There is no file to commit, please execute the `git add` command to add the commit file." )
2730 }
2831 return nil
2932}
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ const (
1313)
1414
1515func init () {
16- runewidth .EastAsianWidth = false
1716 runewidth .DefaultCondition .EastAsianWidth = false
1817}
1918
@@ -37,16 +36,32 @@ type model struct {
3736}
3837
3938func (m model ) Init () tea.Cmd {
40- return nil
39+ return func () tea.Msg {
40+ err := repoCheck ()
41+ if err != nil {
42+ return done {err : err }
43+ }
44+
45+ err = hasStagedFiles ()
46+ if err != nil {
47+ return done {err : err }
48+ }
49+
50+ return nil
51+ }
4152}
4253
4354func (m * model ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
4455 switch msg .(type ) {
4556 case done : // If the view returns a done message, it means that the stage has been processed
4657 // Copy error
4758 m .err = msg .(done ).err
48- // Call the next view
49- m .viewIndex ++
59+ if m .err == nil {
60+ // Call the next view
61+ m .viewIndex ++
62+ } else {
63+ m .viewIndex = RESULT
64+ }
5065
5166 // some special views need to determine the state of the data to update
5267 switch m .viewIndex {
You can’t perform that action at this time.
0 commit comments