GetCommitRangeFileDiffs returns per-line additions and deletions for files changed between two commits. Inputs are the same as `git diff from..to`.
(repoPath, fromCommit, toCommit string)
| 97 | // GetCommitRangeFileDiffs returns per-line additions and deletions for files |
| 98 | // changed between two commits. Inputs are the same as `git diff from..to`. |
| 99 | func GetCommitRangeFileDiffs(repoPath, fromCommit, toCommit string) (map[string]vcs.FileDiff, error) { |
| 100 | if !isGitRepository(repoPath) { |
| 101 | return nil, fmt.Errorf("%s is not a git repository", repoPath) |
| 102 | } |
| 103 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 104 | if err != nil { |
| 105 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 106 | } |
| 107 | |
| 108 | stdout, stderr, err := runGitCommand(repoPath, "diff", "--unified=0", "--no-color", fromCommit, toCommit) |
| 109 | if err != nil { |
| 110 | return nil, gitCommandError(err, stderr) |
| 111 | } |
| 112 | return absolutize(repoRoot, parseUnifiedDiff(string(stdout))), nil |
| 113 | } |
| 114 | |
| 115 | func absolutize(repoRoot string, diffs map[string]vcs.FileDiff) map[string]vcs.FileDiff { |
| 116 | out := make(map[string]vcs.FileDiff, len(diffs)) |
no test coverage detected