all repos — legit @ ab30497e169cd3bfcd122e668c3cdde6bd48305b

web frontend for git, written in go

git: file content at ref
Anirudh Oppiliappan x@icyphox.sh
Sun, 11 Dec 2022 14:18:25 +0530
commit

ab30497e169cd3bfcd122e668c3cdde6bd48305b

parent

6857a2f002358c47f588c8417482a5afd01725d0

1 files changed, 19 insertions(+), 0 deletions(-)

jump to
M git/git.gogit/git.go

@@ -64,6 +64,25 @@

return files, nil } +func FileContentAtRef(r *git.Repository, hash plumbing.Hash, path string) (string, error) { + c, err := r.CommitObject(hash) + if err != nil { + return "", fmt.Errorf("commit object: %w", err) + } + + tree, err := c.Tree() + if err != nil { + return "", fmt.Errorf("file tree: %w", err) + } + + file, err := tree.File(path) + if err != nil { + return "", err + } + + return file.Contents() +} + func makeNiceTree(es []object.TreeEntry) []NiceTree { nts := []NiceTree{} for _, e := range es {