← history for internal/gitrepo/files.go
48f16394internal/gitrepo/files.go14 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
package gitrepo

import "os/exec"

// ReadFile returns the raw bytes of a file at the given branch and path by
// running "git show <branch>:<path>". Works for bare and non-bare repositories.
func ReadFile(repoPath, branch, filePath string) ([]byte, error) {
    cmd := exec.Command("git", "-C", repoPath, "show", branch+":"+filePath)
    out, err := cmd.Output()
    if err != nil {
        return nil, err
    }
    return out, nil
}