parseRenamedFilePath parses a renamed file path from git numstat output and returns the new (destination) file path. Handles two formats: 1. Full format: "old_path => new_path" (returns new_path) 2. Abbreviated format: "prefix/{old => new}/suffix" (returns prefix/new/suffix)
(filePath string)
| 416 | // 1. Full format: "old_path => new_path" (returns new_path) |
| 417 | // 2. Abbreviated format: "prefix/{old => new}/suffix" (returns prefix/new/suffix) |
| 418 | func parseRenamedFilePath(filePath string) string { |
| 419 | // Check for abbreviated rename format: "prefix/{ => new}/suffix" or "prefix/{old => new}/suffix" |
| 420 | if strings.Contains(filePath, "{") && strings.Contains(filePath, "}") { |
| 421 | // Find the positions of { and } |
| 422 | openBrace := strings.Index(filePath, "{") |
| 423 | closeBrace := strings.Index(filePath, "}") |
| 424 | |
| 425 | if openBrace < closeBrace { |
| 426 | // Extract parts |
| 427 | prefix := filePath[:openBrace] |
| 428 | middle := filePath[openBrace+1 : closeBrace] |
| 429 | suffix := filePath[closeBrace+1:] |
| 430 | |
| 431 | // Split the middle part on " => " |
| 432 | if strings.Contains(middle, " => ") { |
| 433 | parts := strings.Split(middle, " => ") |
| 434 | if len(parts) == 2 { |
| 435 | // Use the new (right) part |
| 436 | newMiddle := strings.TrimSpace(parts[1]) |
| 437 | return prefix + newMiddle + suffix |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // Check for full rename format: "old => new" |
| 444 | if strings.Contains(filePath, " => ") { |
| 445 | renameParts := strings.Split(filePath, " => ") |
| 446 | if len(renameParts) == 2 { |
| 447 | return strings.TrimSpace(renameParts[1]) |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // Not a rename, return as-is |
| 452 | return filePath |
| 453 | } |
| 454 | |
| 455 | // isNewStatus determines if a git status code represents a new or untracked file |
| 456 | func isNewStatus(status string) bool { |
no outgoing calls