GetCommitRangeRenames returns git's rename detection between two commits.
(repoPath, fromCommit, toCommit string)
| 142 | |
| 143 | // GetCommitRangeRenames returns git's rename detection between two commits. |
| 144 | func GetCommitRangeRenames(repoPath, fromCommit, toCommit string) (map[string]string, error) { |
| 145 | if !isGitRepository(repoPath) { |
| 146 | return nil, fmt.Errorf("%s is not a git repository (use 'git init' to initialize)", repoPath) |
| 147 | } |
| 148 | if err := validateCommit(repoPath, fromCommit); err != nil { |
| 149 | return nil, err |
| 150 | } |
| 151 | if err := validateCommit(repoPath, toCommit); err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 155 | if err != nil { |
| 156 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 157 | } |
| 158 | |
| 159 | stdout, stderr, err := runGitCommand(repoPath, "diff", "-M", "--diff-filter=R", "--name-status", fromCommit, toCommit) |
| 160 | if err != nil { |
| 161 | return nil, gitCommandError(err, stderr) |
| 162 | } |
| 163 | return parseRenameNameStatus(stdout, repoRoot), nil |
| 164 | } |
| 165 | |
| 166 | // parseRenameNameStatus parses `--name-status` rename rows ("R<score>\told\tnew") |
| 167 | // into an absolute old->new map, or nil when there are none. |
no test coverage detected