aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-09-06 22:05:00 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2018-09-06 22:05:00 +0200
commitd3cec13ac0b195bfb897ed038a08b5130ab9969e (patch)
treeb54b622402057e530cc4b05fb2ffa36767ba726e /worktree_commit.go
parent174f373cf066afc3e3be35576adf3709b0ee278b (diff)
parentf0c4318e7b8d5cbf91723c71a4ba20d1bd0cfaf5 (diff)
downloadgo-git-d3cec13ac0b195bfb897ed038a08b5130ab9969e.tar.gz
worktree: solve merge conflictsv4.7.0
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 b83bf0c..673eb16 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -3,6 +3,7 @@ package git
import (
"bytes"
"path"
+ "sort"
"strings"
"golang.org/x/crypto/openpgp"
@@ -188,7 +189,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