updateCrossReferences rewrites dependency and parent references in all task files.
(reassignments []reassignment, allTasks []*model.Task, refOverrides map[string]string)
| 379 | |
| 380 | // updateCrossReferences rewrites dependency and parent references in all task files. |
| 381 | func updateCrossReferences(reassignments []reassignment, allTasks []*model.Task, refOverrides map[string]string) error { |
| 382 | renamedPaths := make(map[string]string, len(reassignments)) |
| 383 | for _, r := range reassignments { |
| 384 | renamedPaths[r.OldFilePath] = r.NewFilePath |
| 385 | } |
| 386 | |
| 387 | for _, task := range allTasks { |
| 388 | filePath := task.FilePath |
| 389 | if newPath, ok := renamedPaths[filePath]; ok { |
| 390 | filePath = newPath |
| 391 | } |
| 392 | |
| 393 | for _, r := range reassignments { |
| 394 | if shouldSkipRewrite(refOverrides, task.FilePath, r.OldID) { |
| 395 | continue |
| 396 | } |
| 397 | |
| 398 | if err := taskfile.ReplaceReference(filePath, r.OldID, r.NewID); err != nil { |
| 399 | return fmt.Errorf("failed to update references in %s: %w", filePath, err) |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return nil |
| 405 | } |
| 406 | |
| 407 | // shouldSkipRewrite checks if an override exists that keeps the original ID for this file+oldID. |
| 408 | func shouldSkipRewrite(refOverrides map[string]string, origFilePath, oldID string) bool { |
no test coverage detected