code.gitea.io/gitea@v1.19.3/modules/git/tree_blob.go (about)

     1  // Copyright 2015 The Gogs Authors. All rights reserved.
     2  // Copyright 2019 The Gitea Authors. All rights reserved.
     3  // SPDX-License-Identifier: MIT
     4  
     5  package git
     6  
     7  // GetBlobByPath get the blob object according the path
     8  func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) {
     9  	entry, err := t.GetTreeEntryByPath(relpath)
    10  	if err != nil {
    11  		return nil, err
    12  	}
    13  
    14  	if !entry.IsDir() && !entry.IsSubModule() {
    15  		return entry.Blob(), nil
    16  	}
    17  
    18  	return nil, ErrNotExist{"", relpath}
    19  }