Skip to content

Commit d225fe3

Browse files
committed
fix(git): fix staged files check failed
fix staged files check failed Signed-off-by: mritd <[email protected]>
1 parent 7f51053 commit d225fe3

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

git_wapper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

ui.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const (
1313
)
1414

1515
func init() {
16-
runewidth.EastAsianWidth = false
1716
runewidth.DefaultCondition.EastAsianWidth = false
1817
}
1918

@@ -37,16 +36,32 @@ type model struct {
3736
}
3837

3938
func (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

4354
func (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 {

0 commit comments

Comments
 (0)