aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-06-19 12:24:28 +0200
committerGitHub <noreply@github.com>2017-06-19 12:24:28 +0200
commit8b17cf05989402408ee1b66953a12ebfdf700aac (patch)
tree512411e012ef8ff2cf1a51e8785d9edb3b4c2332 /worktree_test.go
parent3ae5d4de35e76f2f573b550d93bb2aed8137f1cb (diff)
parentada10c2978a6c7dea8109f2d92dd092f57f9de84 (diff)
downloadgo-git-8b17cf05989402408ee1b66953a12ebfdf700aac.tar.gz
Merge pull request #436 from mcuadros/symlink
worktree: symlink support
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{