GetCommitRangeDeletedFiles finds all files deleted between two commits. Returns absolute paths. Their content should be read from fromCommit.
(repoPath, fromCommit, toCommit string)
| 319 | // GetCommitRangeDeletedFiles finds all files deleted between two commits. |
| 320 | // Returns absolute paths. Their content should be read from fromCommit. |
| 321 | func GetCommitRangeDeletedFiles(repoPath, fromCommit, toCommit string) ([]string, error) { |
| 322 | if _, err := os.Stat(repoPath); os.IsNotExist(err) { |
| 323 | return nil, fmt.Errorf("repository path does not exist: %s", repoPath) |
| 324 | } |
| 325 | if !isGitRepository(repoPath) { |
| 326 | return nil, fmt.Errorf("%s is not a git repository (use 'git init' to initialize)", repoPath) |
| 327 | } |
| 328 | if err := validateCommit(repoPath, fromCommit); err != nil { |
| 329 | return nil, err |
| 330 | } |
| 331 | if err := validateCommit(repoPath, toCommit); err != nil { |
| 332 | return nil, err |
| 333 | } |
| 334 | |
| 335 | repoRoot, err := GetRepositoryRoot(repoPath) |
| 336 | if err != nil { |
| 337 | return nil, fmt.Errorf("failed to get repository root: %w", err) |
| 338 | } |
| 339 | |
| 340 | stdout, stderr, err := runGitCommand(repoPath, "diff", "--name-only", "--diff-filter=D", fromCommit, toCommit) |
| 341 | if err != nil { |
| 342 | return nil, gitCommandError(err, stderr) |
| 343 | } |
| 344 | |
| 345 | return toAbsolutePaths(repoRoot, parseNonEmptyLines(stdout)), nil |
| 346 | } |
| 347 | |
| 348 | func parseNonEmptyLines(stdout []byte) []string { |
| 349 | var files []string |