39 lines
601 B
Go
39 lines
601 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"sort"
|
|
|
|
"github.com/go-git/go-git/v5/plumbing/object"
|
|
)
|
|
|
|
type gitFS struct{ *object.Tree }
|
|
|
|
func (fs gitFS) Open(path string) (r io.ReadCloser, err error) {
|
|
f, err := fs.Tree.File(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return f.Reader()
|
|
}
|
|
|
|
func (fs gitFS) List(path string) (entries []string, err error) {
|
|
tree, err := fs.Tree.Tree(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
entries = make([]string, 0, len(tree.Entries))
|
|
|
|
for _, ent := range tree.Entries {
|
|
if !ent.Mode.IsFile() {
|
|
continue
|
|
}
|
|
|
|
entries = append(entries, ent.Name)
|
|
}
|
|
|
|
sort.Strings(entries)
|
|
return
|
|
}
|