← history for internal/gitrepo/files.go
f861c317internal/gitrepo/files.go24 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * AltGit - altgit
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2026
 */

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
}