aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-10-25 01:02:41 +0200
committerGitHub <noreply@github.com>2020-10-25 01:02:41 +0200
commitab7eca4a86cc97e787c59dff78bb347952393c48 (patch)
tree73b6885d4a43e367e7f68c329e158191ab9b999f
parent064a96f808d0affc3240ab28036df69d95496335 (diff)
parentca4020f4fa35fa7f4d62cc465ed1edc92ff98896 (diff)
downloadgit-bug-ab7eca4a86cc97e787c59dff78bb347952393c48.tar.gz
Merge pull request #474 from MichaelMure/gogit-sorted-tree
repository: workaround a go-git bug and ensure sorted tree object
-rw-r--r--repository/gogit.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/repository/gogit.go b/repository/gogit.go
index efa8cda1..b30effb5 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -8,6 +8,7 @@ import (
"os/exec"
stdpath "path"
"path/filepath"
+ "sort"
"strings"
"sync"
"time"
@@ -359,7 +360,22 @@ func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error) {
func (repo *GoGitRepo) StoreTree(mapping []TreeEntry) (Hash, error) {
var tree object.Tree
- for _, entry := range mapping {
+ // TODO: can be removed once https://github.com/go-git/go-git/issues/193 is resolved
+ sorted := make([]TreeEntry, len(mapping))
+ copy(sorted, mapping)
+ sort.Slice(sorted, func(i, j int) bool {
+ nameI := sorted[i].Name
+ if sorted[i].ObjectType == Tree {
+ nameI += "/"
+ }
+ nameJ := sorted[j].Name
+ if sorted[j].ObjectType == Tree {
+ nameJ += "/"
+ }
+ return nameI < nameJ
+ })
+
+ for _, entry := range sorted {
mode := filemode.Regular
if entry.ObjectType == Tree {
mode = filemode.Dir