@@ -2,19 +2,24 @@ package git
22
33import (
44 "bytes"
5+ "io/ioutil"
6+ "os"
7+ "os/exec"
58 "strings"
69 "time"
710
8- "golang.org/x/crypto/openpgp"
9- "golang.org/x/crypto/openpgp/armor"
10- "golang.org/x/crypto/openpgp/errors"
1111 "gopkg.in/src-d/go-git.v4/plumbing"
1212 "gopkg.in/src-d/go-git.v4/plumbing/object"
1313 "gopkg.in/src-d/go-git.v4/plumbing/storer"
14+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
1415 "gopkg.in/src-d/go-git.v4/storage/memory"
1516
17+ "golang.org/x/crypto/openpgp"
18+ "golang.org/x/crypto/openpgp/armor"
19+ "golang.org/x/crypto/openpgp/errors"
1620 . "gopkg.in/check.v1"
1721 "gopkg.in/src-d/go-billy.v4/memfs"
22+ "gopkg.in/src-d/go-billy.v4/osfs"
1823 "gopkg.in/src-d/go-billy.v4/util"
1924)
2025
@@ -196,6 +201,54 @@ func (s *WorktreeSuite) TestCommitSignBadKey(c *C) {
196201 c .Assert (err , Equals , errors .InvalidArgumentError ("signing key is encrypted" ))
197202}
198203
204+ func (s * WorktreeSuite ) TestCommitTreeSort (c * C ) {
205+ path , err := ioutil .TempDir (os .TempDir (), "test-commit-tree-sort" )
206+ c .Assert (err , IsNil )
207+ fs := osfs .New (path )
208+ st , err := filesystem .NewStorage (fs )
209+ c .Assert (err , IsNil )
210+ r , err := Init (st , nil )
211+ c .Assert (err , IsNil )
212+
213+ r , err = Clone (memory .NewStorage (), memfs .New (), & CloneOptions {
214+ URL : path ,
215+ })
216+
217+ w , err := r .Worktree ()
218+ c .Assert (err , IsNil )
219+
220+ mfs := w .Filesystem
221+
222+ err = mfs .MkdirAll ("delta" , 0755 )
223+ c .Assert (err , IsNil )
224+
225+ for _ , p := range []string {"delta_last" , "Gamma" , "delta/middle" , "Beta" , "delta-first" , "alpha" } {
226+ util .WriteFile (mfs , p , []byte ("foo" ), 0644 )
227+ _ , err = w .Add (p )
228+ c .Assert (err , IsNil )
229+ }
230+
231+ _ , err = w .Commit ("foo\n " , & CommitOptions {
232+ All : true ,
233+ Author : defaultSignature (),
234+ })
235+ c .Assert (err , IsNil )
236+
237+ err = r .Push (& PushOptions {})
238+ c .Assert (err , IsNil )
239+
240+ cmd := exec .Command ("git" , "fsck" )
241+ cmd .Dir = path
242+ cmd .Env = os .Environ ()
243+ buf := & bytes.Buffer {}
244+ cmd .Stderr = buf
245+ cmd .Stdout = buf
246+
247+ err = cmd .Run ()
248+
249+ c .Assert (err , IsNil , Commentf ("%s" , buf .Bytes ()))
250+ }
251+
199252func assertStorageStatus (
200253 c * C , r * Repository ,
201254 treesCount , blobCount , commitCount int , head plumbing.Hash ,
0 commit comments