MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / GetFileContentFromCommit

Function GetFileContentFromCommit

vcs/git/git_diff.go:360–380  ·  view source on GitHub ↗

GetFileContentFromCommit reads the content of a file at a specific commit using 'git show commit:path'. The filePath should be relative to the repository root.

(repoPath, commitID, filePath string)

Source from the content-addressed store, hash-verified

358// GetFileContentFromCommit reads the content of a file at a specific commit
359// using 'git show commit:path'. The filePath should be relative to the repository root.
360func GetFileContentFromCommit(repoPath, commitID, filePath string) ([]byte, error) {
361 if err := validateGitRef(commitID); err != nil {
362 return nil, err
363 }
364 if err := validateGitRelPath(filePath); err != nil {
365 return nil, err
366 }
367
368 // Format: commit:path
369 ref := fmt.Sprintf("%s:%s", commitID, filePath)
370
371 stdout, stderr, err := runGitCommand(repoPath, "show", ref)
372 if err != nil {
373 if stderr != "" {
374 return nil, fmt.Errorf("git show failed: %s", stderr)
375 }
376 return nil, err
377 }
378
379 return stdout, nil
380}
381
382// GetCommitRangeFiles finds all files changed between two commits.
383// Uses: git diff --name-only --diff-filter=d <from> <to>

Calls 3

validateGitRefFunction · 0.85
validateGitRelPathFunction · 0.85
runGitCommandFunction · 0.85