repo_tree.go 687 B

123456789101112131415161718192021222324252627
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. func (repo *Repository) getTree(id sha1) (*Tree, error) {
  6. treePath := filepathFromSHA1(repo.Path, id.String())
  7. if isFile(treePath) {
  8. _, err := NewCommand("ls-tree", id.String()).RunInDir(repo.Path)
  9. if err != nil {
  10. return nil, ErrNotExist{id.String(), ""}
  11. }
  12. }
  13. return NewTree(repo, id), nil
  14. }
  15. // Find the tree object in the repository.
  16. func (repo *Repository) GetTree(idStr string) (*Tree, error) {
  17. id, err := NewIDFromString(idStr)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return repo.getTree(id)
  22. }