diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-21 13:01:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-21 13:01:30 +0200 |
commit | d98ebb5e42cd07007010f6d10db11a792c58206e (patch) | |
tree | d53451935a81f90f4da8727a6af1d61952712ae8 /worktree_test.go | |
parent | 0f2abe7da065ed25085ea265db20e77609cefdbc (diff) | |
parent | 52add52ea3f92a2a092e6879b6d75fb1279430d5 (diff) | |
download | go-git-d98ebb5e42cd07007010f6d10db11a792c58206e.tar.gz |
Merge pull request #395 from mcuadros/rm-mv
worktree: Remove and Move methods
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 110 |
1 files changed, 110 insertions, 0 deletions
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) +} |