aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit_test.go
diff options
context:
space:
mode:
authorMark Bartel <github@spottybenny.ca>2018-07-02 14:34:22 -0400
committerMark Bartel <github@spottybenny.ca>2018-07-03 17:19:09 -0400
commite1c269422ab209443b80f05095627c2795e32fd5 (patch)
tree1ec18a0cc99fbec80d08b15c1af94936bc6af42a /worktree_commit_test.go
parentb11eaabdfd82deb68537fd44176d58084a6f367d (diff)
downloadgo-git-e1c269422ab209443b80f05095627c2795e32fd5.tar.gz
worktree: add test for correct tree sorting (issue #881)
Signed-off-by: Mark Bartel <github@spottybenny.ca>
Diffstat (limited to 'worktree_commit_test.go')
-rw-r--r--worktree_commit_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 5575bca..2100626 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -8,9 +8,15 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/memory"
+ "bytes"
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-billy.v4/memfs"
+ "gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-billy.v4/util"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
+ "io/ioutil"
+ "os"
+ "os/exec"
)
func (s *WorktreeSuite) TestCommitInvalidOptions(c *C) {
@@ -135,6 +141,54 @@ func (s *WorktreeSuite) TestRemoveAndCommitAll(c *C) {
assertStorageStatus(c, s.Repository, 13, 11, 11, expected)
}
+func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
+ path, err := ioutil.TempDir(os.TempDir(), "test-commit-tree-sort")
+ c.Assert(err, IsNil)
+ fs := osfs.New(path)
+ st, err := filesystem.NewStorage(fs)
+ c.Assert(err, IsNil)
+ r, err := Init(st, nil)
+ c.Assert(err, IsNil)
+
+ r, err = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
+ URL: path,
+ })
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ mfs := w.Filesystem
+
+ err = mfs.MkdirAll("delta", 0755)
+ c.Assert(err, IsNil)
+
+ for _, p := range []string{"delta_last", "Gamma", "delta/middle", "Beta", "delta-first", "alpha"} {
+ util.WriteFile(mfs, p, []byte("foo"), 0644)
+ _, err = w.Add(p)
+ c.Assert(err, IsNil)
+ }
+
+ _, err = w.Commit("foo\n", &CommitOptions{
+ All: true,
+ Author: defaultSignature(),
+ })
+ c.Assert(err, IsNil)
+
+ err = r.Push(&PushOptions{})
+ c.Assert(err, IsNil)
+
+ cmd := exec.Command("git", "fsck")
+ cmd.Dir = path
+ cmd.Env = os.Environ()
+ buf := &bytes.Buffer{}
+ cmd.Stderr = buf
+ cmd.Stdout = buf
+
+ err = cmd.Run()
+
+ c.Assert(err, IsNil, Commentf("%s", buf.Bytes()))
+}
+
func assertStorageStatus(
c *C, r *Repository,
treesCount, blobCount, commitCount int, head plumbing.Hash,