@@ -3,7 +3,6 @@ package git
33import (
44 "bytes"
55 "context"
6- "errors"
76 "io"
87 "io/ioutil"
98 "os"
@@ -2167,6 +2166,8 @@ func (s *WorktreeSuite) TestGrep(c *C) {
21672166}
21682167
21692168func (s * WorktreeSuite ) TestAddAndCommit (c * C ) {
2169+ expectedFiles := 2
2170+
21702171 dir , clean := s .TemporalDir ()
21712172 defer clean ()
21722173
@@ -2176,29 +2177,58 @@ func (s *WorktreeSuite) TestAddAndCommit(c *C) {
21762177 w , err := repo .Worktree ()
21772178 c .Assert (err , IsNil )
21782179
2180+ os .WriteFile (filepath .Join (dir , "foo" ), []byte ("bar" ), 0o644 )
2181+ os .WriteFile (filepath .Join (dir , "bar" ), []byte ("foo" ), 0o644 )
2182+
21792183 _ , err = w .Add ("." )
21802184 c .Assert (err , IsNil )
21812185
2182- w .Commit ("Test Add And Commit" , & CommitOptions {Author : & object.Signature {
2186+ _ , err = w .Commit ("Test Add And Commit" , & CommitOptions {Author : & object.Signature {
21832187 Name : "foo" ,
21842188 Email : "foo@foo.foo" ,
21852189 When : time .Now (),
21862190 }})
2191+ c .Assert (err , IsNil )
21872192
21882193 iter , err := w .r .Log (& LogOptions {})
21892194 c .Assert (err , IsNil )
2195+
2196+ filesFound := 0
21902197 err = iter .ForEach (func (c * object.Commit ) error {
21912198 files , err := c .Files ()
21922199 if err != nil {
21932200 return err
21942201 }
21952202
21962203 err = files .ForEach (func (f * object.File ) error {
2197- return errors .New ("Expected no files, got at least 1" )
2204+ filesFound ++
2205+ return nil
21982206 })
21992207 return err
22002208 })
22012209 c .Assert (err , IsNil )
2210+ c .Assert (filesFound , Equals , expectedFiles )
2211+ }
2212+
2213+ func (s * WorktreeSuite ) TestAddAndCommitEmpty (c * C ) {
2214+ dir , clean := s .TemporalDir ()
2215+ defer clean ()
2216+
2217+ repo , err := PlainInit (dir , false )
2218+ c .Assert (err , IsNil )
2219+
2220+ w , err := repo .Worktree ()
2221+ c .Assert (err , IsNil )
2222+
2223+ _ , err = w .Add ("." )
2224+ c .Assert (err , IsNil )
2225+
2226+ _ , err = w .Commit ("Test Add And Commit" , & CommitOptions {Author : & object.Signature {
2227+ Name : "foo" ,
2228+ Email : "foo@foo.foo" ,
2229+ When : time .Now (),
2230+ }})
2231+ c .Assert (err , Equals , ErrEmptyCommit )
22022232}
22032233
22042234func (s * WorktreeSuite ) TestLinkedWorktree (c * C ) {
0 commit comments