summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/git/repo_tree.go9
-rw-r--r--modules/git/tree.go9
-rw-r--r--modules/git/tree_entry.go8
-rw-r--r--modules/repofiles/tree.go2
4 files changed, 17 insertions, 11 deletions
diff --git a/modules/git/repo_tree.go b/modules/git/repo_tree.go
index 8a024fe6ac..8bb7291744 100644
--- a/modules/git/repo_tree.go
+++ b/modules/git/repo_tree.go
@@ -35,14 +35,15 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
if err != nil {
return nil, err
}
+ resolvedID := id
commitObject, err := repo.gogitRepo.CommitObject(plumbing.Hash(id))
- if err != nil {
- return nil, err
+ if err == nil {
+ id = SHA1(commitObject.TreeHash)
}
- treeObject, err := repo.getTree(SHA1(commitObject.TreeHash))
+ treeObject, err := repo.getTree(id)
if err != nil {
return nil, err
}
- treeObject.CommitID = id
+ treeObject.ResolvedID = resolvedID
return treeObject, nil
}
diff --git a/modules/git/tree.go b/modules/git/tree.go
index 8f55d7a8c5..6ca893cb7b 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -15,9 +15,9 @@ import (
// Tree represents a flat directory listing.
type Tree struct {
- ID SHA1
- CommitID SHA1
- repo *Repository
+ ID SHA1
+ ResolvedID SHA1
+ repo *Repository
gogitTree *object.Tree
@@ -106,7 +106,7 @@ func (t *Tree) ListEntriesRecursive() (Entries, error) {
seen := map[plumbing.Hash]bool{}
walker := object.NewTreeWalker(t.gogitTree, true, seen)
for {
- _, entry, err := walker.Next()
+ fullName, entry, err := walker.Next()
if err == io.EOF {
break
}
@@ -121,6 +121,7 @@ func (t *Tree) ListEntriesRecursive() (Entries, error) {
ID: entry.Hash,
gogitTreeEntry: &entry,
ptree: t,
+ fullName: fullName,
}
entries = append(entries, convertedEntry)
}
diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go
index fe2fd14f97..6019e34487 100644
--- a/modules/git/tree_entry.go
+++ b/modules/git/tree_entry.go
@@ -40,12 +40,16 @@ type TreeEntry struct {
gogitTreeEntry *object.TreeEntry
ptree *Tree
- size int64
- sized bool
+ size int64
+ sized bool
+ fullName string
}
// Name returns the name of the entry
func (te *TreeEntry) Name() string {
+ if te.fullName != "" {
+ return te.fullName
+ }
return te.gogitTreeEntry.Name
}
diff --git a/modules/repofiles/tree.go b/modules/repofiles/tree.go
index 5b4e7aeb28..e189fe1229 100644
--- a/modules/repofiles/tree.go
+++ b/modules/repofiles/tree.go
@@ -23,7 +23,7 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs
}
}
tree := new(api.GitTreeResponse)
- tree.SHA = gitTree.CommitID.String()
+ tree.SHA = gitTree.ResolvedID.String()
tree.URL = repo.APIURL() + "/git/trees/" + tree.SHA
var entries git.Entries
if recursive {