Skip to content

Report a gone upstream from Status() as IsUpstreamGone [minor] - #218

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/177-upstream-gone
Oct 14, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/177-upstream-gone

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #177

What was wrong

Porcelain v2 prints # branch.upstream origin/feat but leaves out # branch.ab when the upstream ref no longer exists, for example after the remote branch was deleted or when it was never fetched. GitStatusParser left Ahead/Behind at their default of 0. A branch with unpushed commits therefore looked in sync, and a caller could decide it was safe to throw away.

Change

  • New GitStatus.IsUpstreamGone. It is true when branch.upstream is present without branch.ab, which is the state git status -sb shows as [gone].
  • The Ahead/Behind docs now say both are 0 while the upstream is gone, and that this does not mean the branch is in sync.
  • I took the issue's additive option instead of making Ahead/Behind int?, so existing callers keep compiling. The change adds public API, hence [minor].

Tests

  • Parser: ReportsAGoneUpstreamWhenTheAheadBehindHeaderIsMissing covers branch.upstream with no branch.ab. Two guards check that a present upstream and no upstream both report not-gone.
  • Integration (GitRemoteSyncTests.StatusReportsAnUpstreamDeletedOnTheRemoteAsGoneAsync): the test pushes feat with upstream to a bare remote, makes one more commit, runs git push origin --delete feat, and then asserts IsUpstreamGone.
  • With the parser change reverted, both the parser test and the integration test fail, and the guards still pass. With the change, everything passes.
  • Full suite: 827/827 passed locally. dotnet format --verify-no-changes is clean on the touched files.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ZJZ6UqCuPy8kj9xX6SHjv


Generated by Claude Code

git prints branch.upstream but no branch.ab when the upstream ref no
longer exists, which left Ahead and Behind at 0 and made a branch with
unpushed commits look in sync. GitStatus.IsUpstreamGone now reports
that state.

Fixes #177

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ZJZ6UqCuPy8kj9xX6SHjv
@sonarqubecloud

Copy link
Copy Markdown

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.

Status() reports Ahead = 0, Behind = 0 when the upstream branch is gone, so unpushed commits look in sync

1 participant