Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Problem

When a branch is behind origin/main and the "Uncommitted" checkbox is enabled in Code Review, inverse deltas (deletions) appear for commits that landed on origin/main after branching.

Root cause: Toggling "Uncommitted" switched between different git diff modes:

  • git diff origin/main...HEAD (three-dot, stable merge-base) when uncommitted=false
  • git diff origin/main (two-dot, tip comparison) when uncommitted=true

The two-dot diff compares the tip of origin/main to the working directory, showing commits Y, Z, W as deletions since they exist on main but not in the feature branch.

Solution

Use explicit git merge-base when includeUncommitted is true:

# includeUncommitted=false (committed only)
git diff origin/main...HEAD

# includeUncommitted=true (committed + uncommitted)
git diff $(git merge-base origin/main HEAD)

Benefits:

  • Stable merge-base: Doesn't change when base ref moves forward
  • Single unified diff: Avoids duplicate hunks from concatenation
  • Clear semantics: "Uncommitted" literally means "include working directory changes"

Test Coverage

Added comprehensive test: "should not show inverse deltas when branch is behind base ref"

  • Creates feature branch from main
  • Adds 3 commits to main after branching (simulates branch falling behind)
  • Adds committed + uncommitted changes to feature branch
  • Verifies: Shows only feature changes, NOT inverse deltas from main

All 662 tests pass ✓

Generated with cmux

Problem: When a branch is behind origin/main and includeUncommitted is enabled,
the Code Review panel would show inverse deltas (deletions) of commits that
landed on origin/main after branching. This happened because toggling
'Uncommitted' switched between:
- git diff origin/main...HEAD (stable merge-base)
- git diff origin/main (two-dot, compares tip to working dir)

The two-dot diff changed the comparison point, showing irrelevant work.

Solution: Use explicit merge-base when includeUncommitted is true:
- git diff $(git merge-base origin/main HEAD)

This maintains a stable merge-base regardless of the uncommitted flag and
produces a single unified diff (no duplicate hunks from concatenation).

Test Coverage:
- Added test case for branch behind base ref scenario
- Verifies no inverse deltas appear from commits on base ref
- All 15 diffParser tests pass

_Generated with `cmux`_
Expanded test to verify that BOTH includeUncommitted=false (three-dot) and
includeUncommitted=true (merge-base) correctly avoid showing inverse deltas
when branch is behind base ref.

This provides comprehensive coverage of both code paths and documents the
key difference: committed-only vs committed+uncommitted.
@ammario ammario merged commit d363128 into main Oct 19, 2025
8 checks passed
@ammario ammario deleted the cr-uncommited branch October 19, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants