| 1416 | } |
| 1417 | |
| 1418 | func (s *WorktreeSuite) TestAddUntracked(c *C) { |
| 1419 | fs := memfs.New() |
| 1420 | w := &Worktree{ |
| 1421 | r: s.Repository, |
| 1422 | Filesystem: fs, |
| 1423 | } |
| 1424 | |
| 1425 | err := w.Checkout(&CheckoutOptions{Force: true}) |
| 1426 | c.Assert(err, IsNil) |
| 1427 | |
| 1428 | idx, err := w.r.Storer.Index() |
| 1429 | c.Assert(err, IsNil) |
| 1430 | c.Assert(idx.Entries, HasLen, 9) |
| 1431 | |
| 1432 | err = util.WriteFile(w.Filesystem, "foo", []byte("FOO"), 0755) |
| 1433 | c.Assert(err, IsNil) |
| 1434 | |
| 1435 | hash, err := w.Add("foo") |
| 1436 | c.Assert(hash.String(), Equals, "d96c7efbfec2814ae0301ad054dc8d9fc416c9b5") |
| 1437 | c.Assert(err, IsNil) |
| 1438 | |
| 1439 | idx, err = w.r.Storer.Index() |
| 1440 | c.Assert(err, IsNil) |
| 1441 | c.Assert(idx.Entries, HasLen, 10) |
| 1442 | |
| 1443 | e, err := idx.Entry("foo") |
| 1444 | c.Assert(err, IsNil) |
| 1445 | c.Assert(e.Hash, Equals, hash) |
| 1446 | c.Assert(e.Mode, Equals, filemode.Executable) |
| 1447 | |
| 1448 | status, err := w.Status() |
| 1449 | c.Assert(err, IsNil) |
| 1450 | c.Assert(status, HasLen, 1) |
| 1451 | |
| 1452 | file := status.File("foo") |
| 1453 | c.Assert(file.Staging, Equals, Added) |
| 1454 | c.Assert(file.Worktree, Equals, Unmodified) |
| 1455 | |
| 1456 | obj, err := w.r.Storer.EncodedObject(plumbing.BlobObject, hash) |
| 1457 | c.Assert(err, IsNil) |
| 1458 | c.Assert(obj, NotNil) |
| 1459 | c.Assert(obj.Size(), Equals, int64(3)) |
| 1460 | } |
| 1461 | |
| 1462 | func (s *WorktreeSuite) TestIgnored(c *C) { |
| 1463 | fs := memfs.New() |