fix(git): 🐛 Show ours blob as Old side in conflict diff view - #113
Conversation
Replace fallback "all-new content" display for conflicted files with proper side-by-side diff between: - Old side: "ours" blob from index conflict (previously unavailable) - New side: current workdir content (with conflict markers) Improves conflict resolution UX by showing actual changes instead of treating conflicted files as entirely new. Falls back to original behavior for binary files or index access failures. Uses `similar` v2.7.0 for line-based diff algorithm with standard context/remove/add hunks, respecting `MAX_DIFF_LINES` truncation. Includes Cargo.toml and Cargo.lock updates for the new dependency.
AI Code Review SummaryPR: #113 (fix(git): 🐛 Show ours blob as Old side in conflict diff view) Overall AssessmentDetected 3 actionable findings, prioritize CRITICAL/HIGH before merge. Major Findings by Severity
Actionable Suggestions
Potential Risks
Test Suggestions
File-Level Coverage Notes
Inline Downgraded Items (processed but not inline)
Coverage Status
Uncovered list:
No-patch covered list:
Runtime/Budget
|
|
|
||
| /// Compare old (ours blob) text with new (workdir) text using `similar` and | ||
| /// produce standard context/remove/add hunk data, respecting MAX_DIFF_LINES. | ||
| fn build_conflict_diff_hunks( |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| // Try to get the ours blob from the index conflict to use as Old side. | ||
| // If that fails (e.g. delete-modify conflict, non-UTF-8 blob), fall | ||
| // back to the previous all-new-content behaviour. | ||
| let ours_text = (|| -> Option<String> { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| // Try to get the ours blob from the index conflict to use as Old side. | ||
| // If that fails (e.g. delete-modify conflict, non-UTF-8 blob), fall | ||
| // back to the previous all-new-content behaviour. | ||
| let ours_text = (|| -> Option<String> { |
There was a problem hiding this comment.
[HIGH] No integration test for ours-blob extraction path in get_unmerged_diff
The new ours-blob extraction logic (L315-331) and the diff construction path (L336-352) are the primary feature addition, yet have no integration test. Existing milestone-style integration tests (src-tauri/tests/) should include a scenario that creates a merge conflict and verifies get_unmerged_diff returns proper old-vs-new hunks.
Suggestion: Add an integration test in src-tauri/tests/ that: (1) creates a repo with a conflicting merge, (2) calls get_unmerged_diff on the conflicted file, (3) asserts the returned hunks contain both Remove and Add lines (not all-Add fallback), and (4) verifies additions/deletions counts are correct.
Confidence: 0.92
| return (Vec::new(), 0, 0, false); | ||
| } | ||
|
|
||
| let old_total = old_line.saturating_sub(1); |
There was a problem hiding this comment.
[MEDIUM] Incorrect hunk header line counts when diff is truncated
When MAX_DIFF_LINES is hit and the loop breaks early, old_total and new_total are computed from the partial iteration counters rather than the actual line counts of the input texts, producing an inaccurate hunk header.
Suggestion: Compute old_total and new_total from the actual input texts (e.g., old_text.lines().count() and new_text.lines().count()) or from TextDiff::old_lines()/new_lines() counts, so the header reflects the true file sizes even when truncated.
Risk: Diff renderers or UI components that rely on the hunk header line counts will display incorrect information for large conflicted files that trigger truncation.
Confidence: 0.92
| }); | ||
| } | ||
|
|
||
| // Fallback: show workdir content as all-new (original behaviour). |
There was a problem hiding this comment.
[MEDIUM] No test for fallback path when ours blob extraction fails
Multiple conditions cause ours_text to be None, triggering the fallback to all-new-content behavior. None of these branches are tested, meaning regressions in fallback behavior would be invisible.
Suggestion: Add integration tests covering at least: (1) a delete-modify conflict where conflict.our is None, (2) a conflict with a binary ours blob, (3) a conflict where the workdir file is missing. Each should verify the fallback GitDiffDto has hunks from build_added_file_fallback_hunks with all Add lines.
Confidence: 0.88
Summary
similarcrateTest Plan
cargo testpasses (6/6)🤖 Generated with TiyCode