Skip to content

fix: correct git diff stats logic and add delete worktree confirmation modal#94

Merged
amandal0903 merged 11 commits intomainfrom
fix-git-diff-logic
Apr 9, 2026
Merged

fix: correct git diff stats logic and add delete worktree confirmation modal#94
amandal0903 merged 11 commits intomainfrom
fix-git-diff-logic

Conversation

@amandal0903
Copy link
Copy Markdown
Collaborator

Description:

  • Fix diff stats computing against wrong base branch — getDiffStats was using git branch --show-current (the local checkout, e.g. test-branch) instead of the remote default branch. Now resolves via git symbolic-ref refs/remotes/origin/HEAD, falling back to main.
  • Fix numstat comparing against merge-base instead of baseRef — squash-merged content already on main still showed as diffs because the fork-point predates the branch. Now uses merge-base only for file discovery/ahead count and baseRef for the actual numstat.
  • Add delete worktree confirmation modal — custom modal (matching addWorktreeModal aesthetic) that lists what will be removed (worktree files, branch, session data) and surfaces diff stats as an "ahead of origin/" warning. Cancel is focused by default to prevent accidental deletion.

Show a custom modal (matching addWorktreeModal aesthetic) before deleting
a worktree. Lists what will be removed (worktree files, branch, session
data) and surfaces uncommitted change stats as a warning. Cancel is
focused by default so Enter alone cannot trigger deletion.
getDiffStats was using `git branch --show-current` to find the base
branch, which returned whatever was checked out locally (e.g.
test-branch) rather than the actual default branch (main). This caused
diff stats to compare against origin/test-branch — often stale —
inflating numbers to +10K lines on branches with no real changes.

Now uses `git symbolic-ref refs/remotes/origin/HEAD` to correctly
resolve the remote's default branch, falling back to 'main'.
Diff stats now use git merge-base instead of origin/main directly,
so numbers reflect only what the branch changed and stay stable when
origin/main moves ahead. Delete modal label changed from "uncommitted
changes will be lost" to "ahead of <default branch>".
…ests

The numstat diff was comparing against the merge-base (fork point) instead
of baseRef (current tip of origin/main). This broke squash-merge detection:
content already on main via squash merge still showed as diffs because the
fork-point predates the branch's changes.

Fix: use merge-base only for file discovery and ahead count; use baseRef
for the actual numstat so squash-merged content correctly resolves to 0.

Also:
- Display "ahead of origin/<default_branch>" in delete modal
- Add tests for defaultBranch detection (main vs master via origin/HEAD)
- Add delete modal test suite (stats text, cancel/delete, ARIA, etc.)
- Fix stale comments that described the old broken logic
@amandal0903 amandal0903 merged commit 22ac15d into main Apr 9, 2026
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.

1 participant