| 1605 | } |
| 1606 | |
| 1607 | func (s *WorktreeSuite) TestAddRemovedInDirectory(c *C) { |
| 1608 | fs := memfs.New() |
| 1609 | w := &Worktree{ |
| 1610 | r: s.Repository, |
| 1611 | Filesystem: fs, |
| 1612 | } |
| 1613 | |
| 1614 | err := w.Checkout(&CheckoutOptions{Force: true}) |
| 1615 | c.Assert(err, IsNil) |
| 1616 | |
| 1617 | idx, err := w.r.Storer.Index() |
| 1618 | c.Assert(err, IsNil) |
| 1619 | c.Assert(idx.Entries, HasLen, 9) |
| 1620 | |
| 1621 | err = w.Filesystem.Remove("go/example.go") |
| 1622 | c.Assert(err, IsNil) |
| 1623 | |
| 1624 | err = w.Filesystem.Remove("json/short.json") |
| 1625 | c.Assert(err, IsNil) |
| 1626 | |
| 1627 | hash, err := w.Add("go") |
| 1628 | c.Assert(err, IsNil) |
| 1629 | c.Assert(hash.IsZero(), Equals, true) |
| 1630 | |
| 1631 | e, err := idx.Entry("go/example.go") |
| 1632 | c.Assert(err, IsNil) |
| 1633 | c.Assert(e.Hash, Equals, plumbing.NewHash("880cd14280f4b9b6ed3986d6671f907d7cc2a198")) |
| 1634 | c.Assert(e.Mode, Equals, filemode.Regular) |
| 1635 | |
| 1636 | e, err = idx.Entry("json/short.json") |
| 1637 | c.Assert(err, IsNil) |
| 1638 | c.Assert(e.Hash, Equals, plumbing.NewHash("c8f1d8c61f9da76f4cb49fd86322b6e685dba956")) |
| 1639 | c.Assert(e.Mode, Equals, filemode.Regular) |
| 1640 | |
| 1641 | status, err := w.Status() |
| 1642 | c.Assert(err, IsNil) |
| 1643 | c.Assert(status, HasLen, 2) |
| 1644 | |
| 1645 | file := status.File("go/example.go") |
| 1646 | c.Assert(file.Staging, Equals, Deleted) |
| 1647 | |
| 1648 | file = status.File("json/short.json") |
| 1649 | c.Assert(file.Staging, Equals, Unmodified) |
| 1650 | } |
| 1651 | |
| 1652 | func (s *WorktreeSuite) TestAddRemovedInDirectoryWithTrailingSlash(c *C) { |
| 1653 | fs := memfs.New() |