aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
blob: 9c5d8e32ffecfd01b0c2d3417efaff95669449e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package git

import (
	"io/ioutil"

	. "gopkg.in/check.v1"
	"srcd.works/go-billy.v1/memory"
)

type WorktreeSuite struct {
	BaseSuite
}

var _ = Suite(&WorktreeSuite{})

func (s *WorktreeSuite) TestCheckout(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)

	entries, err := fs.ReadDir("/")
	c.Assert(err, IsNil)

	c.Assert(entries, HasLen, 8)
	ch, err := fs.Open("CHANGELOG")
	c.Assert(err, IsNil)

	content, err := ioutil.ReadAll(ch)
	c.Assert(err, IsNil)
	c.Assert(string(content), Equals, "Initial changelog\n")
}