| 405 | } |
| 406 | |
| 407 | func (s *WorktreeSuite) TestCheckoutKeep(c *C) { |
| 408 | w := &Worktree{ |
| 409 | r: s.Repository, |
| 410 | Filesystem: memfs.New(), |
| 411 | } |
| 412 | |
| 413 | err := w.Checkout(&CheckoutOptions{ |
| 414 | Force: true, |
| 415 | }) |
| 416 | c.Assert(err, IsNil) |
| 417 | |
| 418 | // Create a new branch and create a new file. |
| 419 | err = w.Checkout(&CheckoutOptions{ |
| 420 | Branch: plumbing.NewBranchReferenceName("new-branch"), |
| 421 | Create: true, |
| 422 | }) |
| 423 | c.Assert(err, IsNil) |
| 424 | |
| 425 | w.Filesystem = memfs.New() |
| 426 | f, err := w.Filesystem.Create("new-file.txt") |
| 427 | c.Assert(err, IsNil) |
| 428 | _, err = f.Write([]byte("DUMMY")) |
| 429 | c.Assert(err, IsNil) |
| 430 | c.Assert(f.Close(), IsNil) |
| 431 | |
| 432 | // Add the file to staging. |
| 433 | _, err = w.Add("new-file.txt") |
| 434 | c.Assert(err, IsNil) |
| 435 | |
| 436 | // Switch branch to master, and verify that the new file was kept in staging. |
| 437 | err = w.Checkout(&CheckoutOptions{ |
| 438 | Keep: true, |
| 439 | }) |
| 440 | c.Assert(err, IsNil) |
| 441 | |
| 442 | fi, err := w.Filesystem.Stat("new-file.txt") |
| 443 | c.Assert(err, IsNil) |
| 444 | c.Assert(fi.Size(), Equals, int64(5)) |
| 445 | } |
| 446 | |
| 447 | func (s *WorktreeSuite) TestCheckoutSymlink(c *C) { |
| 448 | if runtime.GOOS == "windows" { |