diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-03 23:37:21 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-03 23:37:21 +0200 |
commit | 2e092f909f643ef455d84dfa59282f0f0adf3c7a (patch) | |
tree | 30f68b00e059945e084c7836ae49c8233a8b4be3 | |
parent | 9a807f4f29c24bf0dc0b44d7cdfc2233cfd128d3 (diff) | |
download | go-git-2e092f909f643ef455d84dfa59282f0f0adf3c7a.tar.gz |
worktree: Status return empty status instead of nil
-rw-r--r-- | worktree_status.go | 8 | ||||
-rw-r--r-- | worktree_test.go | 17 |
2 files changed, 23 insertions, 2 deletions
diff --git a/worktree_status.go b/worktree_status.go index 46922da..f78a0c2 100644 --- a/worktree_status.go +++ b/worktree_status.go @@ -4,6 +4,8 @@ import ( "bytes" "io" + "fmt" + "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/format/index" @@ -19,7 +21,7 @@ import ( func (w *Worktree) Status() (Status, error) { ref, err := w.r.Head() if err == plumbing.ErrReferenceNotFound { - return nil, nil + return make(Status, 0), nil } if err != nil { @@ -177,7 +179,9 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) { return h, err } - if s.File(path).Worktree == Unmodified { + fmt.Println(len(s)) + fs := s.File(path) + if fs != nil && fs.Worktree == Unmodified { return h, nil } diff --git a/worktree_test.go b/worktree_test.go index f06a1f9..1da86c9 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -9,6 +9,7 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/filemode" "gopkg.in/src-d/go-git.v4/plumbing/format/index" "gopkg.in/src-d/go-git.v4/plumbing/object" + "gopkg.in/src-d/go-git.v4/storage/memory" "github.com/src-d/go-git-fixtures" . "gopkg.in/check.v1" @@ -290,6 +291,22 @@ func (s *WorktreeSuite) TestStatus(c *C) { c.Assert(status, HasLen, 9) } +func (s *WorktreeSuite) TestStatusEmpty(c *C) { + fs := memfs.New() + storage := memory.NewStorage() + + r, err := Init(storage, fs) + c.Assert(err, IsNil) + + w, err := r.Worktree() + c.Assert(err, IsNil) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status.IsClean(), Equals, true) + c.Assert(status, NotNil) +} + func (s *WorktreeSuite) TestReset(c *C) { fs := memfs.New() w := &Worktree{ |