summaryrefslogtreecommitdiffstats
path: root/modules/git/repo_tree.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git/repo_tree.go')
-rw-r--r--modules/git/repo_tree.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/modules/git/repo_tree.go b/modules/git/repo_tree.go
index 3fa491d529..8a024fe6ac 100644
--- a/modules/git/repo_tree.go
+++ b/modules/git/repo_tree.go
@@ -1,19 +1,23 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
+import (
+ "gopkg.in/src-d/go-git.v4/plumbing"
+)
+
func (repo *Repository) getTree(id SHA1) (*Tree, error) {
- treePath := filepathFromSHA1(repo.Path, id.String())
- if isFile(treePath) {
- _, err := NewCommand("ls-tree", id.String()).RunInDir(repo.Path)
- if err != nil {
- return nil, ErrNotExist{id.String(), ""}
- }
+ gogitTree, err := repo.gogitRepo.TreeObject(plumbing.Hash(id))
+ if err != nil {
+ return nil, err
}
- return NewTree(repo, id), nil
+ tree := NewTree(repo, id)
+ tree.gogitTree = gogitTree
+ return tree, nil
}
// GetTree find the tree object in the repository.
@@ -31,5 +35,14 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
if err != nil {
return nil, err
}
- return repo.getTree(id)
+ commitObject, err := repo.gogitRepo.CommitObject(plumbing.Hash(id))
+ if err != nil {
+ return nil, err
+ }
+ treeObject, err := repo.getTree(SHA1(commitObject.TreeHash))
+ if err != nil {
+ return nil, err
+ }
+ treeObject.CommitID = id
+ return treeObject, nil
}