diff options
author | Linuxer Wang <linuxerwang@gmail.com> | 2019-05-03 09:46:54 -0700 |
---|---|---|
committer | Linuxer Wang <linuxerwang@gmail.com> | 2019-05-15 23:02:27 -0700 |
commit | d1e34a7675bf8bb95f3c40c27d446adc5862eb62 (patch) | |
tree | 53bfb94ef1a2ed250b9edc60f803d6066314e29a /worktree_test.go | |
parent | 24de5efe77a202ddba83abb4d14095474dcdf1f6 (diff) | |
download | go-git-d1e34a7675bf8bb95f3c40c27d446adc5862eb62.tar.gz |
Keep local changes when checkout branch in worktree.
Signed-off-by: Linuxer Wang <linuxerwang@gmail.com>
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go index afedc91..045a76d 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -314,6 +314,46 @@ func (s *WorktreeSuite) TestCheckoutForce(c *C) { c.Assert(entries, HasLen, 8) } +func (s *WorktreeSuite) TestCheckoutKeep(c *C) { + w := &Worktree{ + r: s.Repository, + Filesystem: memfs.New(), + } + + err := w.Checkout(&CheckoutOptions{ + Force: true, + }) + c.Assert(err, IsNil) + + // Create a new branch and create a new file. + err = w.Checkout(&CheckoutOptions{ + Branch: plumbing.NewBranchReferenceName("new-branch"), + Create: true, + }) + c.Assert(err, IsNil) + + w.Filesystem = memfs.New() + f, err := w.Filesystem.Create("new-file.txt") + c.Assert(err, IsNil) + _, err = f.Write([]byte("DUMMY")) + c.Assert(err, IsNil) + c.Assert(f.Close(), IsNil) + + // Add the file to staging. + _, err = w.Add("new-file.txt") + c.Assert(err, IsNil) + + // Switch branch to master, and verify that the new file was kept in staging. + err = w.Checkout(&CheckoutOptions{ + Keep: true, + }) + c.Assert(err, IsNil) + + fi, err := w.Filesystem.Stat("new-file.txt") + c.Assert(err, IsNil) + c.Assert(fi.Size(), Equals, int64(5)) +} + func (s *WorktreeSuite) TestCheckoutSymlink(c *C) { if runtime.GOOS == "windows" { c.Skip("git doesn't support symlinks by default in windows") |