diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-26 16:25:29 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-26 16:25:29 +0200 |
commit | 9e8f1cfde0e4fd6e4893ca53dea3145fe0182800 (patch) | |
tree | 810cff49f55719b84fe72f1433696e0dc4a2881b /worktree_test.go | |
parent | d32489902e86c6b667bbc4d28558ebd40a80cf4a (diff) | |
download | go-git-9e8f1cfde0e4fd6e4893ca53dea3145fe0182800.tar.gz |
worktree: add method
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go index 3393469..f06a1f9 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -12,6 +12,7 @@ import ( "github.com/src-d/go-git-fixtures" . "gopkg.in/check.v1" + "gopkg.in/src-d/go-billy.v2" "gopkg.in/src-d/go-billy.v2/memfs" "gopkg.in/src-d/go-billy.v2/osfs" ) @@ -478,3 +479,96 @@ func (s *WorktreeSuite) TestSubmodules(c *C) { c.Assert(l, HasLen, 2) } + +func (s *WorktreeSuite) TestAddUntracked(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + fs: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + idx, err := w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 9) + + err = billy.WriteFile(w.fs, "foo", []byte("FOO"), 0755) + c.Assert(err, IsNil) + + hash, err := w.Add("foo") + c.Assert(hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") + c.Assert(err, IsNil) + + idx, err = w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 10) + + e, err := idx.Entry("foo") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, hash) + c.Assert(e.Mode, Equals, filemode.Executable) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 1) + + file := status.File("foo") + c.Assert(file.Staging, Equals, Added) + c.Assert(file.Worktree, Equals, Unmodified) +} + +func (s *WorktreeSuite) TestAddModified(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + fs: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + idx, err := w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 9) + + err = billy.WriteFile(w.fs, "LICENSE", []byte("FOO"), 0644) + c.Assert(err, IsNil) + + hash, err := w.Add("LICENSE") + c.Assert(err, IsNil) + c.Assert(hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") + + idx, err = w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 9) + + e, err := idx.Entry("LICENSE") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, hash) + c.Assert(e.Mode, Equals, filemode.Regular) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 1) + + file := status.File("LICENSE") + c.Assert(file.Staging, Equals, Modified) + c.Assert(file.Worktree, Equals, Unmodified) +} + +func (s *WorktreeSuite) TestAddUnmodified(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + fs: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + hash, err := w.Add("LICENSE") + c.Assert(hash.String(), Equals, "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f") + c.Assert(err, IsNil) +} |