findTaskChangesFromDiff runs git diff --cached, parses all status changes, and matches them against scanned tasks.
(tasks []*model.Task, scanDir string)
| 398 | // findTaskChangesFromDiff runs git diff --cached, parses all status changes, |
| 399 | // and matches them against scanned tasks. |
| 400 | func findTaskChangesFromDiff(tasks []*model.Task, scanDir string) (TaskChanges, error) { |
| 401 | var changes TaskChanges |
| 402 | |
| 403 | diffOutput, err := gitDiffFunc(scanDir) |
| 404 | if err != nil { |
| 405 | return changes, fmt.Errorf("git diff failed: %w", err) |
| 406 | } |
| 407 | |
| 408 | dr := parseDiffResult(diffOutput) |
| 409 | if dr.IsEmpty() { |
| 410 | return changes, nil |
| 411 | } |
| 412 | |
| 413 | gitRoot, err := resolveGitRoot(scanDir) |
| 414 | if err != nil { |
| 415 | return changes, err |
| 416 | } |
| 417 | |
| 418 | // Build absolute path sets for each category. |
| 419 | absMap := func(files []string) map[string]bool { |
| 420 | m := make(map[string]bool, len(files)) |
| 421 | for _, f := range files { |
| 422 | m[filepath.Clean(filepath.Join(gitRoot, f))] = true |
| 423 | } |
| 424 | return m |
| 425 | } |
| 426 | completedSet := absMap(dr.Completed) |
| 427 | addedSet := absMap(dr.Added) |
| 428 | startedSet := absMap(dr.Started) |
| 429 | blockedSet := absMap(dr.Blocked) |
| 430 | cancelledSet := absMap(dr.Cancelled) |
| 431 | |
| 432 | for _, t := range tasks { |
| 433 | cleaned := filepath.Clean(t.FilePath) |
| 434 | switch { |
| 435 | case completedSet[cleaned]: |
| 436 | changes.Completed = append(changes.Completed, t) |
| 437 | case addedSet[cleaned]: |
| 438 | changes.Added = append(changes.Added, t) |
| 439 | case startedSet[cleaned]: |
| 440 | changes.Started = append(changes.Started, t) |
| 441 | case blockedSet[cleaned]: |
| 442 | changes.Blocked = append(changes.Blocked, t) |
| 443 | case cancelledSet[cleaned]: |
| 444 | changes.Cancelled = append(changes.Cancelled, t) |
| 445 | } |
| 446 | } |
| 447 | return changes, nil |
| 448 | } |
| 449 | |
| 450 | // gitRootFunc resolves the git repository root. Override in tests. |
| 451 | var gitRootFunc = defaultGitRoot |
no test coverage detected