Skip to content

Diff badge stops counting work that already merged - #277

Merged
pallaoro merged 1 commit into
mainfrom
why-does-it-tell-me-merged
Oct 6, 2026
Merged

pallaoro merged 1 commit into
mainfrom
why-does-it-tell-me-merged

Conversation

@pallaoro

@pallaoro pallaoro commented Oct 6, 2026

Copy link
Copy Markdown
Member

After a squash merge done outside Ateam (an agent's gh pr merge), a task kept showing the whole branch as changes (+5465 on a task whose PR had merged) and its card said closed.

Why

  • The badge counted git diff --merge-base origin/<base>. A squash or rebase merge never moves the merge-base, so merged lines counted forever.
  • origin/<base> was never fetched after a merge outside Ateam.
  • detectMerged asked about task.branch, but agents and loop runs cut fresh branches inside their worktree.
  • When one file had both committed and unstaged edits, the unstaged count overwrote the committed one.

Change

  • diff/fileDiff: files the branch no longer contributes (git merge-tree --write-tree, in memory, no index lock) count only edits on top of HEAD. Conflicted files count as landed when base held HEAD's exact version at some point since the fork. Older git, or no origin/<base>, keeps today's numbers.
  • The sweep and the gitDiff RPC fetch origin/<base> first: once per repo per 5 min, 5s cap, reusing fetchBase.
  • detectMerged follows the worktree's current branch.
  • With a base set, one --merge-base pass already covers the working tree, so the staged/unstaged override is dropped.

Verified

  • 4 new git-core tests; 3 fail on the old code. Disabling the history recheck brings back the created-file regression.
  • Typecheck passes; server 357/357 and git-core 61/61 tests pass.
  • Against the real worktrees: clawnify-integrations goes from +5465 to +54 (only the untracked .codex/), PR #2286 merged (was closed). openvideo goes to +0, #2288 merged.

Ceiling: committing again on a file after it was squash-merged falls back to the full merge-base count for that file.

A squash or rebase merge never moves the merge-base, so the badge kept every
merged line forever (+5465 on a task whose PR had landed). Count what the
branch would still contribute to origin/<base> instead, via an in-memory
git merge-tree, with a base-history check for files base edited again.

Also: fetch origin/<base> (per repo, throttled) before counting, follow the
worktree's current branch when detecting merges, and stop unstaged edits
overwriting the committed count for the same file.
@pallaoro
pallaoro merged commit dd30852 into main Oct 6, 2026
1 check passed
@pallaoro pallaoro mentioned this pull request Oct 10, 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