diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-15 23:13:45 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-04-15 23:13:45 +0200 |
commit | 4b0fc1eb6937b6e5f8569794e8b669443e2c7584 (patch) | |
tree | 9f2fdb086be2b96ff9c2169fdb93e19e5a298490 /utils/merkletrie/filesystem/node_test.go | |
parent | 601c85a8834cd78e317f1ba435475fa18162053a (diff) | |
download | go-git-4b0fc1eb6937b6e5f8569794e8b669443e2c7584.tar.gz |
worktree: reset and checkout support for submodules
Diffstat (limited to 'utils/merkletrie/filesystem/node_test.go')
-rw-r--r-- | utils/merkletrie/filesystem/node_test.go | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/utils/merkletrie/filesystem/node_test.go b/utils/merkletrie/filesystem/node_test.go index b7c124d..f783c15 100644 --- a/utils/merkletrie/filesystem/node_test.go +++ b/utils/merkletrie/filesystem/node_test.go @@ -9,6 +9,7 @@ import ( . "gopkg.in/check.v1" "gopkg.in/src-d/go-billy.v2" "gopkg.in/src-d/go-billy.v2/memfs" + "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/utils/merkletrie" "gopkg.in/src-d/go-git.v4/utils/merkletrie/noder" ) @@ -30,7 +31,12 @@ func (s *NoderSuite) TestDiff(c *C) { WriteFile(fsB, "qux/bar", []byte("foo"), 0644) WriteFile(fsB, "qux/qux", []byte("foo"), 0644) - ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals) + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, nil), + NewRootNode(fsB, nil), + IsEquals, + ) + c.Assert(err, IsNil) c.Assert(ch, HasLen, 0) } @@ -46,7 +52,12 @@ func (s *NoderSuite) TestDiffChangeContent(c *C) { WriteFile(fsB, "qux/bar", []byte("bar"), 0644) WriteFile(fsB, "qux/qux", []byte("foo"), 0644) - ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals) + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, nil), + NewRootNode(fsB, nil), + IsEquals, + ) + c.Assert(err, IsNil) c.Assert(ch, HasLen, 1) } @@ -58,7 +69,12 @@ func (s *NoderSuite) TestDiffChangeMissing(c *C) { fsB := memfs.New() WriteFile(fsB, "bar", []byte("bar"), 0644) - ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals) + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, nil), + NewRootNode(fsB, nil), + IsEquals, + ) + c.Assert(err, IsNil) c.Assert(ch, HasLen, 2) } @@ -70,7 +86,12 @@ func (s *NoderSuite) TestDiffChangeMode(c *C) { fsB := memfs.New() WriteFile(fsB, "foo", []byte("foo"), 0755) - ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals) + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, nil), + NewRootNode(fsB, nil), + IsEquals, + ) + c.Assert(err, IsNil) c.Assert(ch, HasLen, 1) } @@ -82,11 +103,41 @@ func (s *NoderSuite) TestDiffChangeModeNotRelevant(c *C) { fsB := memfs.New() WriteFile(fsB, "foo", []byte("foo"), 0655) - ch, err := merkletrie.DiffTree(NewRootNode(fsA), NewRootNode(fsB), IsEquals) + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, nil), + NewRootNode(fsB, nil), + IsEquals, + ) + c.Assert(err, IsNil) c.Assert(ch, HasLen, 0) } +func (s *NoderSuite) TestDiffDirectory(c *C) { + fsA := memfs.New() + fsA.MkdirAll("qux/bar", 0644) + + fsB := memfs.New() + fsB.MkdirAll("qux/bar", 0644) + + ch, err := merkletrie.DiffTree( + NewRootNode(fsA, map[string]plumbing.Hash{ + "qux/bar": plumbing.NewHash("aa102815663d23f8b75a47e7a01965dcdc96468c"), + }), + NewRootNode(fsB, map[string]plumbing.Hash{ + "qux/bar": plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"), + }), + IsEquals, + ) + + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 1) + + a, err := ch[0].Action() + c.Assert(err, IsNil) + c.Assert(a, Equals, merkletrie.Modify) +} + func WriteFile(fs billy.Filesystem, filename string, data []byte, perm os.FileMode) error { f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) if err != nil { |