diff options
author | ThinkChaos <ThinkChaos@users.noreply.github.com> | 2023-03-07 10:10:26 -0500 |
---|---|---|
committer | ThinkChaos <ThinkChaos@users.noreply.github.com> | 2023-05-30 12:21:19 -0400 |
commit | cb287f782ad8b5847a721d3f06265a0e9750d41f (patch) | |
tree | 119ef4399fb53013bd363e71efe8036682037263 /worktree_test.go | |
parent | d37c8b92eb84a2b66413262c33812236b91422f9 (diff) | |
download | go-git-cb287f782ad8b5847a721d3f06265a0e9750d41f.tar.gz |
worktree: minor speedup for doAddDirectory
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go index ea55ac6..24d5bd5 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -1488,6 +1488,96 @@ func (s *WorktreeSuite) TestAddRemovedInDirectory(c *C) { c.Assert(file.Staging, Equals, Unmodified) } +func (s *WorktreeSuite) TestAddRemovedInDirectoryWithTrailingSlash(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + Filesystem: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + idx, err := w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 9) + + err = w.Filesystem.Remove("go/example.go") + c.Assert(err, IsNil) + + err = w.Filesystem.Remove("json/short.json") + c.Assert(err, IsNil) + + hash, err := w.Add("go/") + c.Assert(err, IsNil) + c.Assert(hash.IsZero(), Equals, true) + + e, err := idx.Entry("go/example.go") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, plumbing.NewHash("880cd14280f4b9b6ed3986d6671f907d7cc2a198")) + c.Assert(e.Mode, Equals, filemode.Regular) + + e, err = idx.Entry("json/short.json") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, plumbing.NewHash("c8f1d8c61f9da76f4cb49fd86322b6e685dba956")) + c.Assert(e.Mode, Equals, filemode.Regular) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 2) + + file := status.File("go/example.go") + c.Assert(file.Staging, Equals, Deleted) + + file = status.File("json/short.json") + c.Assert(file.Staging, Equals, Unmodified) +} + +func (s *WorktreeSuite) TestAddRemovedInDirectoryDot(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + Filesystem: fs, + } + + err := w.Checkout(&CheckoutOptions{Force: true}) + c.Assert(err, IsNil) + + idx, err := w.r.Storer.Index() + c.Assert(err, IsNil) + c.Assert(idx.Entries, HasLen, 9) + + err = w.Filesystem.Remove("go/example.go") + c.Assert(err, IsNil) + + err = w.Filesystem.Remove("json/short.json") + c.Assert(err, IsNil) + + hash, err := w.Add(".") + c.Assert(err, IsNil) + c.Assert(hash.IsZero(), Equals, true) + + e, err := idx.Entry("go/example.go") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, plumbing.NewHash("880cd14280f4b9b6ed3986d6671f907d7cc2a198")) + c.Assert(e.Mode, Equals, filemode.Regular) + + e, err = idx.Entry("json/short.json") + c.Assert(err, IsNil) + c.Assert(e.Hash, Equals, plumbing.NewHash("c8f1d8c61f9da76f4cb49fd86322b6e685dba956")) + c.Assert(e.Mode, Equals, filemode.Regular) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status, HasLen, 2) + + file := status.File("go/example.go") + c.Assert(file.Staging, Equals, Deleted) + + file = status.File("json/short.json") + c.Assert(file.Staging, Equals, Deleted) +} + func (s *WorktreeSuite) TestAddSymlink(c *C) { dir, clean := s.TemporalDir() defer clean() |