| 808 | } |
| 809 | |
| 810 | func (s *WorktreeSuite) TestCheckoutBranchUntracked(c *C) { |
| 811 | w := &Worktree{ |
| 812 | r: s.Repository, |
| 813 | Filesystem: memfs.New(), |
| 814 | } |
| 815 | |
| 816 | uf, err := w.Filesystem.Create("untracked_file") |
| 817 | c.Assert(err, IsNil) |
| 818 | _, err = uf.Write([]byte("don't delete me")) |
| 819 | c.Assert(err, IsNil) |
| 820 | |
| 821 | err = w.Checkout(&CheckoutOptions{ |
| 822 | Branch: "refs/heads/branch", |
| 823 | }) |
| 824 | c.Assert(err, IsNil) |
| 825 | |
| 826 | head, err := w.r.Head() |
| 827 | c.Assert(err, IsNil) |
| 828 | c.Assert(head.Name().String(), Equals, "refs/heads/branch") |
| 829 | |
| 830 | status, err := w.Status() |
| 831 | c.Assert(err, IsNil) |
| 832 | // The untracked file should still be there, so it's not clean |
| 833 | c.Assert(status.IsClean(), Equals, false) |
| 834 | c.Assert(status.IsUntracked("untracked_file"), Equals, true) |
| 835 | err = w.Filesystem.Remove("untracked_file") |
| 836 | c.Assert(err, IsNil) |
| 837 | status, err = w.Status() |
| 838 | c.Assert(err, IsNil) |
| 839 | // After deleting the untracked file it should now be clean |
| 840 | c.Assert(status.IsClean(), Equals, true) |
| 841 | } |
| 842 | |
| 843 | func (s *WorktreeSuite) TestCheckoutCreateWithHash(c *C) { |
| 844 | w := &Worktree{ |