aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit.go
diff options
context:
space:
mode:
authorMark Bartel <github@spottybenny.ca>2018-07-03 17:20:57 -0400
committerMark Bartel <github@spottybenny.ca>2018-07-03 17:20:57 -0400
commit7ff71b5a66eea98983c610d33523041a5a829e2f (patch)
treec89c53b9c308b10f43753b99e61f33d2ef2d6bf5 /worktree_commit.go
parente1c269422ab209443b80f05095627c2795e32fd5 (diff)
downloadgo-git-7ff71b5a66eea98983c610d33523041a5a829e2f.tar.gz
worktree: sort the tree object. Fixes #881
Signed-off-by: Mark Bartel <github@spottybenny.ca>
Diffstat (limited to 'worktree_commit.go')
-rw-r--r--worktree_commit.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/worktree_commit.go b/worktree_commit.go
index 5fa63ab..ee5cd82 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -11,6 +11,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage"
"gopkg.in/src-d/go-billy.v4"
+ "sort"
)
// Commit stores the current contents of the index in a new commit along with
@@ -162,7 +163,20 @@ func (h *buildTreeHelper) doBuildTree(e *index.Entry, parent, fullpath string) {
h.trees[parent].Entries = append(h.trees[parent].Entries, te)
}
+type sortableEntries []object.TreeEntry
+
+func (sortableEntries) sortName(te object.TreeEntry) string {
+ if te.Mode == filemode.Dir {
+ return te.Name + "/"
+ }
+ return te.Name
+}
+func (se sortableEntries) Len() int { return len(se) }
+func (se sortableEntries) Less(i int, j int) bool { return se.sortName(se[i]) < se.sortName(se[j]) }
+func (se sortableEntries) Swap(i int, j int) { se[i], se[j] = se[j], se[i] }
+
func (h *buildTreeHelper) copyTreeToStorageRecursive(parent string, t *object.Tree) (plumbing.Hash, error) {
+ sort.Sort(sortableEntries(t.Entries))
for i, e := range t.Entries {
if e.Mode != filemode.Dir && !e.Hash.IsZero() {
continue