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

Function GetCommitFileDiffs

vcs/git/git_diff_lines.go:73–95  ·  view source on GitHub ↗

GetCommitFileDiffs returns per-line additions and deletions for files modified in a single commit, computed against that commit's first parent. Line numbers in Additions reference the commit's post-image; line numbers in Deletions reference the parent's content.

(repoPath, commitID string)

Source from the content-addressed store, hash-verified

71// Line numbers in Additions reference the commit's post-image; line numbers
72// in Deletions reference the parent's content.
73func GetCommitFileDiffs(repoPath, commitID string) (map[string]vcs.FileDiff, error) {
74 if !isGitRepository(repoPath) {
75 return nil, fmt.Errorf("%s is not a git repository", repoPath)
76 }
77 repoRoot, err := GetRepositoryRoot(repoPath)
78 if err != nil {
79 return nil, fmt.Errorf("failed to get repository root: %w", err)
80 }
81
82 // `git diff <commit>~ <commit>` is undefined for the root commit; fall back
83 // to `--root <commit>` which diffs against the empty tree.
84 stdout, _, err := runGitCommand(repoPath, "diff", "--unified=0", "--no-color", commitID+"~", commitID)
85 if err != nil {
86 // Root commit has no parent; fall back to diff-tree --root which emits
87 // a synthetic diff against the empty tree.
88 var stderr string
89 stdout, stderr, err = runGitCommand(repoPath, "diff-tree", "--root", "--unified=0", "--no-color", "-p", commitID)
90 if err != nil {
91 return nil, gitCommandError(err, stderr)
92 }
93 }
94 return absolutize(repoRoot, parseUnifiedDiff(string(stdout))), nil
95}
96
97// GetCommitRangeFileDiffs returns per-line additions and deletions for files
98// changed between two commits. Inputs are the same as `git diff from..to`.

Callers 3

annotateRustPhantomsFunction · 0.92
TestGetCommitFileDiffsFunction · 0.85

Calls 6

isGitRepositoryFunction · 0.85
GetRepositoryRootFunction · 0.85
runGitCommandFunction · 0.85
gitCommandErrorFunction · 0.85
absolutizeFunction · 0.85
parseUnifiedDiffFunction · 0.85

Tested by 2

TestGetCommitFileDiffsFunction · 0.68