| 196 | } |
| 197 | |
| 198 | func BlobContent(ref Ref, path string, repoDir string) ([]byte, bool, error) { |
| 199 | if ref.IsEmpty() { |
| 200 | ref = NewRef("HEAD") |
| 201 | } |
| 202 | // Use `git show ref:path` to get the blob content at that ref |
| 203 | cmd := exec.Command("git", "show", ref.String()+":"+path) |
| 204 | if repoDir != "" { |
| 205 | cmd.Dir = repoDir |
| 206 | } |
| 207 | out, err := cmd.Output() |
| 208 | if err != nil { |
| 209 | // include stderr if available |
| 210 | if ee, ok := err.(*exec.ExitError); ok { |
| 211 | return nil, false, fmt.Errorf("git show failed: %v: %s", err, string(ee.Stderr)) |
| 212 | } |
| 213 | return nil, false, fmt.Errorf("git show failed: %w", err) |
| 214 | } |
| 215 | return out, IsBinary(out), nil |
| 216 | } |
| 217 | |
| 218 | func Commits(ref Ref, repoDir string) ([]Commit, error) { |
| 219 | format := []string{ |