aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'worktree_test.go')
-rw-r--r--worktree_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 9efa231..06f82ca 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -56,6 +56,35 @@ func (s *WorktreeSuite) TestCheckout(c *C) {
c.Assert(idx.Entries, HasLen, 9)
}
+func (s *WorktreeSuite) TestCheckoutSymlink(c *C) {
+ dir, err := ioutil.TempDir("", "checkout")
+ defer os.RemoveAll(dir)
+
+ r, err := PlainInit(dir, false)
+ c.Assert(err, IsNil)
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ w.fs.Symlink("not-exists", "bar")
+ w.Add("bar")
+ w.Commit("foo", &CommitOptions{Author: defaultSignature()})
+
+ r.Storer.SetIndex(&index.Index{Version: 2})
+ w.fs = osfs.New(filepath.Join(dir, "worktree-empty"))
+
+ err = w.Checkout(&CheckoutOptions{})
+ c.Assert(err, IsNil)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ c.Assert(status.IsClean(), Equals, true)
+
+ target, err := w.fs.Readlink("bar")
+ c.Assert(target, Equals, "not-exists")
+ c.Assert(err, IsNil)
+}
+
func (s *WorktreeSuite) TestCheckoutSubmodule(c *C) {
url := "https://github.com/git-fixtures/submodule.git"
w := &Worktree{
@@ -641,6 +670,28 @@ func (s *WorktreeSuite) TestAddUnmodified(c *C) {
c.Assert(err, IsNil)
}
+func (s *WorktreeSuite) TestAddSymlink(c *C) {
+ dir, err := ioutil.TempDir("", "checkout")
+ defer os.RemoveAll(dir)
+
+ r, err := PlainInit(dir, false)
+ c.Assert(err, IsNil)
+ err = util.WriteFile(r.wt, "foo", []byte("qux"), 0644)
+ c.Assert(err, IsNil)
+ err = r.wt.Symlink("foo", "bar")
+ c.Assert(err, IsNil)
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+ h, err := w.Add("foo")
+ c.Assert(err, IsNil)
+ c.Assert(h, Not(Equals), plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"))
+
+ h, err = w.Add("bar")
+ c.Assert(err, IsNil)
+ c.Assert(h, Equals, plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"))
+}
+
func (s *WorktreeSuite) TestRemove(c *C) {
fs := memfs.New()
w := &Worktree{