aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-29 02:17:01 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-01-29 02:17:01 +0100
commit352170d1bf8cc7b32b85d8a2740eb3627e952a6e (patch)
treeba9cdd6b32b0871a78fcd91aee90a388dd3e2326 /worktree_test.go
parentde1c0bfec0269ff2a31b62d13612d833da178ec4 (diff)
downloadgo-git-352170d1bf8cc7b32b85d8a2740eb3627e952a6e.tar.gz
worktree, status implementation
Diffstat (limited to 'worktree_test.go')
-rw-r--r--worktree_test.go129
1 files changed, 129 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 9c5d8e3..62b0a03 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -1,10 +1,15 @@
package git
import (
+ "fmt"
"io/ioutil"
+ "os"
+
+ "gopkg.in/src-d/go-git.v4/plumbing/format/index"
. "gopkg.in/check.v1"
"srcd.works/go-billy.v1/memory"
+ osfs "srcd.works/go-billy.v1/os"
)
type WorktreeSuite struct {
@@ -13,6 +18,12 @@ type WorktreeSuite struct {
var _ = Suite(&WorktreeSuite{})
+func (s *WorktreeSuite) SetUpTest(c *C) {
+ s.buildBasicRepository(c)
+ // the index is removed if not the Repository will be not clean
+ c.Assert(s.Repository.s.SetIndex(&index.Index{Version: 2}), IsNil)
+}
+
func (s *WorktreeSuite) TestCheckout(c *C) {
h, err := s.Repository.Head()
c.Assert(err, IsNil)
@@ -36,4 +47,122 @@ func (s *WorktreeSuite) TestCheckout(c *C) {
content, err := ioutil.ReadAll(ch)
c.Assert(err, IsNil)
c.Assert(string(content), Equals, "Initial changelog\n")
+
+ idx, err := s.Repository.s.Index()
+ c.Assert(err, IsNil)
+ c.Assert(idx.Entries, HasLen, 9)
+}
+
+func (s *WorktreeSuite) TestCheckoutIndexMemory(c *C) {
+ h, err := s.Repository.Head()
+ c.Assert(err, IsNil)
+
+ fs := memory.New()
+ w := &Worktree{
+ r: s.Repository,
+ fs: fs,
+ }
+
+ err = w.Checkout(h.Hash())
+ c.Assert(err, IsNil)
+
+ idx, err := s.Repository.s.Index()
+ c.Assert(err, IsNil)
+ c.Assert(idx.Entries, HasLen, 9)
+ c.Assert(idx.Entries[0].Hash.String(), Equals, "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88")
+ c.Assert(idx.Entries[0].Name, Equals, ".gitignore")
+ // in memoryfs the perms are not supported
+ c.Assert(idx.Entries[0].Mode, Equals, os.FileMode(0))
+ c.Assert(idx.Entries[0].ModifiedAt.IsZero(), Equals, false)
+ c.Assert(idx.Entries[0].Size, Equals, uint32(189))
+
+ // ctime, dev, inode, uid and gid are not supported on memory fs
+ c.Assert(idx.Entries[0].CreatedAt.IsZero(), Equals, true)
+ c.Assert(idx.Entries[0].Dev, Equals, uint32(0))
+ c.Assert(idx.Entries[0].Inode, Equals, uint32(0))
+ c.Assert(idx.Entries[0].UID, Equals, uint32(0))
+ c.Assert(idx.Entries[0].GID, Equals, uint32(0))
+}
+
+func (s *WorktreeSuite) TestCheckoutIndexOS(c *C) {
+ h, err := s.Repository.Head()
+ c.Assert(err, IsNil)
+
+ dir, err := ioutil.TempDir("", "checkout")
+ defer os.RemoveAll(dir)
+
+ fs := osfs.New(dir)
+ w := &Worktree{
+ r: s.Repository,
+ fs: fs,
+ }
+
+ err = w.Checkout(h.Hash())
+ c.Assert(err, IsNil)
+
+ idx, err := s.Repository.s.Index()
+ c.Assert(err, IsNil)
+ c.Assert(idx.Entries, HasLen, 9)
+ c.Assert(idx.Entries[0].Hash.String(), Equals, "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88")
+ c.Assert(idx.Entries[0].Name, Equals, ".gitignore")
+ c.Assert(idx.Entries[0].Mode, Equals, os.FileMode(0644))
+ c.Assert(idx.Entries[0].ModifiedAt.IsZero(), Equals, false)
+ c.Assert(idx.Entries[0].Size, Equals, uint32(189))
+
+ c.Assert(idx.Entries[0].CreatedAt.IsZero(), Equals, false)
+ c.Assert(idx.Entries[0].Dev, Not(Equals), uint32(0))
+ c.Assert(idx.Entries[0].Inode, Not(Equals), uint32(0))
+ c.Assert(idx.Entries[0].UID, Not(Equals), uint32(0))
+ c.Assert(idx.Entries[0].GID, Not(Equals), uint32(0))
+}
+
+func (s *WorktreeSuite) TestStatus(c *C) {
+
+ h, err := s.Repository.Head()
+ c.Assert(err, IsNil)
+
+ fs := memory.New()
+ w := &Worktree{
+ r: s.Repository,
+ fs: fs,
+ }
+
+ err = w.Checkout(h.Hash())
+ c.Assert(err, IsNil)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+
+ fmt.Println(status)
+ c.Assert(status.IsClean(), Equals, true)
+}
+
+func (s *WorktreeSuite) TestStatusModified(c *C) {
+ c.Assert(s.Repository.s.SetIndex(&index.Index{Version: 2}), IsNil)
+
+ h, err := s.Repository.Head()
+ c.Assert(err, IsNil)
+
+ dir, err := ioutil.TempDir("", "status")
+ defer os.RemoveAll(dir)
+
+ fs := osfs.New(dir)
+ w := &Worktree{
+ r: s.Repository,
+ fs: fs,
+ }
+
+ err = w.Checkout(h.Hash())
+ c.Assert(err, IsNil)
+
+ f, err := fs.Create(".gitignore")
+ c.Assert(err, IsNil)
+ _, err = f.Write([]byte("foo"))
+ c.Assert(err, IsNil)
+ err = f.Close()
+ c.Assert(err, IsNil)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ c.Assert(status.IsClean(), Equals, false)
}