From 52add52ea3f92a2a092e6879b6d75fb1279430d5 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 21 May 2017 12:54:29 +0200 Subject: worktree: Remove and Move methods --- worktree_test.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'worktree_test.go') diff --git a/worktree_test.go b/worktree_test.go index 68760f2..6ca2ed0 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -590,3 +590,113 @@ func (s *WorktreeSuite) TestAddUnmodified(c *C) { c.Assert(hash.String(), Equals, "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f") c.Assert(err, IsNil) } + +func (s *WorktreeSuite) TestRemove(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.Remove("LICENSE") + c.Assert(hash.String(), Equals, "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f") + c.Assert(err, IsNil) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 1) + c.Assert(status.File("LICENSE").Staging, Equals, Deleted) +} + +func (s *WorktreeSuite) TestRemoveNotExistentEntry(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.Remove("not-exists") + c.Assert(hash.IsZero(), Equals, true) + c.Assert(err, NotNil) +} + +func (s *WorktreeSuite) TestRemoveDeletedFromWorktree(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + fs: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + err = fs.Remove("LICENSE") + c.Assert(err, IsNil) + + hash, err := w.Remove("LICENSE") + c.Assert(hash.String(), Equals, "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f") + c.Assert(err, IsNil) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 1) + c.Assert(status.File("LICENSE").Staging, Equals, Deleted) +} + +func (s *WorktreeSuite) TestMove(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.Move("LICENSE", "foo") + c.Check(hash.String(), Equals, "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f") + c.Assert(err, IsNil) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 2) + c.Assert(status.File("LICENSE").Staging, Equals, Deleted) + c.Assert(status.File("foo").Staging, Equals, Added) + +} + +func (s *WorktreeSuite) TestMoveNotExistentEntry(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.Move("not-exists", "foo") + c.Assert(hash.IsZero(), Equals, true) + c.Assert(err, NotNil) +} + +func (s *WorktreeSuite) TestMoveToExistent(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.Move(".gitignore", "LICENSE") + c.Assert(hash.IsZero(), Equals, true) + c.Assert(err, Equals, ErrDestinationExists) +} -- cgit