aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:36:37 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:36:37 +0200
commitada10c2978a6c7dea8109f2d92dd092f57f9de84 (patch)
tree5bfe6efbe152d1c90bf14a12681afbc74accb7d3 /worktree_test.go
parent1fd0a4963b4a5002b23bf4faa7814adca73818d6 (diff)
downloadgo-git-ada10c2978a6c7dea8109f2d92dd092f57f9de84.tar.gz
worktree: support for symlinks
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 4f15005..c7d3b78 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{
@@ -591,6 +620,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{