getCommitRangeFileStatuses returns a map of file paths to their status codes for a commit range
(repoPath, fromCommit, toCommit string)
| 370 | |
| 371 | // getCommitRangeFileStatuses returns a map of file paths to their status codes for a commit range |
| 372 | func getCommitRangeFileStatuses(repoPath, fromCommit, toCommit string) (map[string]string, error) { |
| 373 | stdout, stderr, err := runGitCommand(repoPath, "diff", "--name-status", fromCommit, toCommit) |
| 374 | if err != nil { |
| 375 | return nil, gitCommandError(err, stderr) |
| 376 | } |
| 377 | |
| 378 | statuses := make(map[string]string) |
| 379 | lines := strings.Split(string(stdout), "\n") |
| 380 | for _, line := range lines { |
| 381 | line = strings.TrimSpace(line) |
| 382 | if line == "" { |
| 383 | continue |
| 384 | } |
| 385 | |
| 386 | parts := strings.Split(line, "\t") |
| 387 | if len(parts) < 2 { |
| 388 | continue |
| 389 | } |
| 390 | |
| 391 | status := parts[0] |
| 392 | var filePath string |
| 393 | if strings.HasPrefix(status, "R") || strings.HasPrefix(status, "C") { |
| 394 | if len(parts) < 3 { |
| 395 | continue |
| 396 | } |
| 397 | filePath = parts[2] |
| 398 | } else { |
| 399 | filePath = parts[1] |
| 400 | } |
| 401 | |
| 402 | if filePath == "" { |
| 403 | continue |
| 404 | } |
| 405 | |
| 406 | normalized := filepath.Clean(filePath) |
| 407 | statuses[normalized] = status |
| 408 | } |
| 409 | |
| 410 | return statuses, nil |
| 411 | } |
| 412 | |
| 413 | // parseRenamedFilePath parses a renamed file path from git numstat output |
| 414 | // and returns the new (destination) file path. |
no test coverage detected