GetCommitRenames returns git's own rename detection for a single commit (old path -> new path, absolute), mirroring `git diff -M`. Old content lives in the commit's first parent.
(repoPath, commitID string)
| 122 | // path -> new path, absolute), mirroring `git diff -M`. Old content lives in the |
| 123 | // commit's first parent. |
| 124 | func GetCommitRenames(repoPath, commitID string) (map[string]string, error) { |
| 125 | if !isGitRepository(repoPath) { |
| 126 | return nil, fmt.Errorf("%s is not a git repository (use 'git init' to initialize)", repoPath) |
| 127 | } |
| 128 | if err := validateCommit(repoPath, commitID); err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 132 | if err != nil { |
| 133 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 134 | } |
| 135 | |
| 136 | stdout, stderr, err := runGitCommand(repoPath, "diff-tree", "-M", "--no-commit-id", "-r", "--root", "--diff-filter=R", "--name-status", commitID) |
| 137 | if err != nil { |
| 138 | return nil, gitCommandError(err, stderr) |
| 139 | } |
| 140 | return parseRenameNameStatus(stdout, repoRoot), nil |
| 141 | } |
| 142 | |
| 143 | // GetCommitRangeRenames returns git's rename detection between two commits. |
| 144 | func GetCommitRangeRenames(repoPath, fromCommit, toCommit string) (map[string]string, error) { |
no test coverage detected