Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit e1c2694

Browse files
committed
worktree: add test for correct tree sorting (issue #881)
Signed-off-by: Mark Bartel <[email protected]>
1 parent b11eaab commit e1c2694

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

worktree_commit_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import (
88
"gopkg.in/src-d/go-git.v4/plumbing/storer"
99
"gopkg.in/src-d/go-git.v4/storage/memory"
1010

11+
"bytes"
1112
. "gopkg.in/check.v1"
1213
"gopkg.in/src-d/go-billy.v4/memfs"
14+
"gopkg.in/src-d/go-billy.v4/osfs"
1315
"gopkg.in/src-d/go-billy.v4/util"
16+
"gopkg.in/src-d/go-git.v4/storage/filesystem"
17+
"io/ioutil"
18+
"os"
19+
"os/exec"
1420
)
1521

1622
func (s *WorktreeSuite) TestCommitInvalidOptions(c *C) {
@@ -135,6 +141,54 @@ func (s *WorktreeSuite) TestRemoveAndCommitAll(c *C) {
135141
assertStorageStatus(c, s.Repository, 13, 11, 11, expected)
136142
}
137143

144+
func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
145+
path, err := ioutil.TempDir(os.TempDir(), "test-commit-tree-sort")
146+
c.Assert(err, IsNil)
147+
fs := osfs.New(path)
148+
st, err := filesystem.NewStorage(fs)
149+
c.Assert(err, IsNil)
150+
r, err := Init(st, nil)
151+
c.Assert(err, IsNil)
152+
153+
r, err = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
154+
URL: path,
155+
})
156+
157+
w, err := r.Worktree()
158+
c.Assert(err, IsNil)
159+
160+
mfs := w.Filesystem
161+
162+
err = mfs.MkdirAll("delta", 0755)
163+
c.Assert(err, IsNil)
164+
165+
for _, p := range []string{"delta_last", "Gamma", "delta/middle", "Beta", "delta-first", "alpha"} {
166+
util.WriteFile(mfs, p, []byte("foo"), 0644)
167+
_, err = w.Add(p)
168+
c.Assert(err, IsNil)
169+
}
170+
171+
_, err = w.Commit("foo\n", &CommitOptions{
172+
All: true,
173+
Author: defaultSignature(),
174+
})
175+
c.Assert(err, IsNil)
176+
177+
err = r.Push(&PushOptions{})
178+
c.Assert(err, IsNil)
179+
180+
cmd := exec.Command("git", "fsck")
181+
cmd.Dir = path
182+
cmd.Env = os.Environ()
183+
buf := &bytes.Buffer{}
184+
cmd.Stderr = buf
185+
cmd.Stdout = buf
186+
187+
err = cmd.Run()
188+
189+
c.Assert(err, IsNil, Commentf("%s", buf.Bytes()))
190+
}
191+
138192
func assertStorageStatus(
139193
c *C, r *Repository,
140194
treesCount, blobCount, commitCount int, head plumbing.Hash,

0 commit comments

Comments
 (0)