aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-18 21:41:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-18 21:41:34 +0200
commit9afc47237c301ecee66619d1ef8ec286185cb070 (patch)
tree5b7d67f820b14db690edcc6f506df64aaf28b717 /worktree_test.go
parentd3c7400c39f86a4c59340c7a9cda8497186e00fc (diff)
downloadgo-git-9afc47237c301ecee66619d1ef8ec286185cb070.tar.gz
worktree: checkout, create branch
Diffstat (limited to 'worktree_test.go')
-rw-r--r--worktree_test.go85
1 files changed, 67 insertions, 18 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 4c9907b..a6c7b06 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -173,47 +173,96 @@ func (s *WorktreeSuite) TestCheckoutIndexOS(c *C) {
c.Assert(idx.Entries[0].GID, Not(Equals), uint32(0))
}
-func (s *WorktreeSuite) TestCheckoutChange(c *C) {
- fs := memfs.New()
+func (s *WorktreeSuite) TestCheckoutBranch(c *C) {
w := &Worktree{
r: s.Repository,
- fs: fs,
+ fs: memfs.New(),
}
- err := w.Checkout(&CheckoutOptions{})
+ err := w.Checkout(&CheckoutOptions{
+ Branch: "refs/heads/branch",
+ })
c.Assert(err, IsNil)
head, err := w.r.Head()
c.Assert(err, IsNil)
- c.Assert(head.Name().String(), Equals, "refs/heads/master")
+ c.Assert(head.Name().String(), Equals, "refs/heads/branch")
status, err := w.Status()
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, true)
+}
- _, err = fs.Stat("README")
- c.Assert(err, Equals, os.ErrNotExist)
- _, err = fs.Stat("vendor")
- c.Assert(err, Equals, nil)
+func (s *WorktreeSuite) TestCheckoutCreateWithHash(c *C) {
+ w := &Worktree{
+ r: s.Repository,
+ fs: memfs.New(),
+ }
- err = w.Checkout(&CheckoutOptions{
- Branch: "refs/heads/branch",
+ err := w.Checkout(&CheckoutOptions{
+ Create: true,
+ Branch: "refs/heads/foo",
+ Hash: plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"),
})
c.Assert(err, IsNil)
- status, err = w.Status()
+ head, err := w.r.Head()
+ c.Assert(err, IsNil)
+ c.Assert(head.Name().String(), Equals, "refs/heads/foo")
+ c.Assert(head.Hash(), Equals, plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"))
+
+ status, err := w.Status()
c.Assert(err, IsNil)
c.Assert(status.IsClean(), Equals, true)
+}
- _, err = fs.Stat("README")
- c.Assert(err, Equals, nil)
+func (s *WorktreeSuite) TestCheckoutCreate(c *C) {
+ w := &Worktree{
+ r: s.Repository,
+ fs: memfs.New(),
+ }
- _, err = fs.Stat("vendor")
- c.Assert(err, Equals, os.ErrNotExist)
+ err := w.Checkout(&CheckoutOptions{
+ Create: true,
+ Branch: "refs/heads/foo",
+ })
+ c.Assert(err, IsNil)
- head, err = w.r.Head()
+ head, err := w.r.Head()
c.Assert(err, IsNil)
- c.Assert(head.Name().String(), Equals, "refs/heads/branch")
+ c.Assert(head.Name().String(), Equals, "refs/heads/foo")
+ c.Assert(head.Hash(), Equals, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ c.Assert(status.IsClean(), Equals, true)
+}
+
+func (s *WorktreeSuite) TestCheckoutBranchAndHash(c *C) {
+ w := &Worktree{
+ r: s.Repository,
+ fs: memfs.New(),
+ }
+
+ err := w.Checkout(&CheckoutOptions{
+ Branch: "refs/heads/foo",
+ Hash: plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"),
+ })
+
+ c.Assert(err, Equals, ErrBranchHashExclusive)
+}
+
+func (s *WorktreeSuite) TestCheckoutCreateMissingBranch(c *C) {
+ w := &Worktree{
+ r: s.Repository,
+ fs: memfs.New(),
+ }
+
+ err := w.Checkout(&CheckoutOptions{
+ Create: true,
+ })
+
+ c.Assert(err, Equals, ErrCreateRequiresBranch)
}
func (s *WorktreeSuite) TestCheckoutTag(c *C) {