fix #84 : properly handle git command errors in GetFileStatistics#111
fix #84 : properly handle git command errors in GetFileStatistics#111DFanso merged 2 commits intoDFanso:mainfrom
Conversation
- Return descriptive errors when git commands fail instead of silently continuing with empty statistics - Prevent misleading "no changes" display when git operations encounter issues - Update tests to expect errors for invalid repository scenarios
fix DFanso#84 : properly handle git command errors in GetFileStatistics
WalkthroughRefactors internal/stats/statistics.go to propagate errors immediately when fetching staged, unstaged, untracked files and collecting line stats, then conditionally process outputs. Updates tests in internal/stats/statistics_test.go to expect errors and nil stats for invalid or non-git directories. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Stats as GetFileStatistics
participant Git as GitHelpers
Caller->>Stats: GetFileStatistics(path)
Stats->>Git: GetStagedFiles(path)
alt error on staged
Git-->>Stats: error
Stats-->>Caller: error
else ok
Git-->>Stats: stagedOutput
Stats->>Git: GetUnstagedFiles(path)
alt error on unstaged
Git-->>Stats: error
Stats-->>Caller: error
else ok
Git-->>Stats: unstagedOutput
Stats->>Git: GetUntrackedFiles(path)
alt error on untracked
Git-->>Stats: error
Stats-->>Caller: error
else ok
Git-->>Stats: untrackedOutput
Stats->>Git: GetStagedLineStats(path)
alt error on line stats
Git-->>Stats: error
Stats-->>Caller: error
else ok
Git-->>Stats: lineStatsOutput
Stats-->>Caller: aggregated stats
end
end
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)internal/stats/statistics_test.go (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
Comment |
Summary by CodeRabbit
Bug Fixes
Refactor
Tests