| 1616 | } |
| 1617 | |
| 1618 | func (s *WorktreeSuite) TestAddUntracked(c *C) { |
| 1619 | fs := memfs.New() |
| 1620 | w := &Worktree{ |
| 1621 | r: s.Repository, |
| 1622 | Filesystem: fs, |
| 1623 | } |
| 1624 | |
| 1625 | err := w.Checkout(&CheckoutOptions{Force: true}) |
| 1626 | c.Assert(err, IsNil) |
| 1627 | |
| 1628 | idx, err := w.r.Storer.Index() |
| 1629 | c.Assert(err, IsNil) |
| 1630 | c.Assert(idx.Entries, HasLen, 9) |
| 1631 | |
| 1632 | err = util.WriteFile(w.Filesystem, "foo", []byte("FOO"), 0755) |
| 1633 | c.Assert(err, IsNil) |
| 1634 | |
| 1635 | hash, err := w.Add("foo") |
| 1636 | c.Assert(hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") |
| 1637 | c.Assert(err, IsNil) |
| 1638 | |
| 1639 | idx, err = w.r.Storer.Index() |
| 1640 | c.Assert(err, IsNil) |
| 1641 | c.Assert(idx.Entries, HasLen, 10) |
| 1642 | |
| 1643 | e, err := idx.Entry("foo") |
| 1644 | c.Assert(err, IsNil) |
| 1645 | c.Assert(e.Hash, Equals, hash) |
| 1646 | c.Assert(e.Mode, Equals, filemode.Executable) |
| 1647 | |
| 1648 | status, err := w.Status() |
| 1649 | c.Assert(err, IsNil) |
| 1650 | c.Assert(status, HasLen, 1) |
| 1651 | |
| 1652 | file := status.File("foo") |
| 1653 | c.Assert(file.Staging, Equals, Added) |
| 1654 | c.Assert(file.Worktree, Equals, Unmodified) |
| 1655 | |
| 1656 | obj, err := w.r.Storer.EncodedObject(plumbing.BlobObject, hash) |
| 1657 | c.Assert(err, IsNil) |
| 1658 | c.Assert(obj, NotNil) |
| 1659 | c.Assert(obj.Size(), Equals, int64(3)) |
| 1660 | } |
| 1661 | |
| 1662 | func (s *WorktreeSuite) TestIgnored(c *C) { |
| 1663 | fs := memfs.New() |