Skip to content

fix(gitinfo)!: resolve the upstream the same way for both columns - #57

Merged
bircni merged 1 commit into
mainfrom
fix/consistent-upstream-resolution
Aug 23, 2026
Merged

fix(gitinfo)!: resolve the upstream the same way for both columns#57
bircni merged 1 commit into
mainfrom
fix/consistent-upstream-resolution

Conversation

@bircni

@bircni bircni commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Warning

Breaking: this changes the reported status for two branch shapes. See Compatibility below.

The bug

The Local and Status columns asked different questions about the same branch.

  • get_ahead_behind_and_local_status used the configured upstream
    (branch.<name>.merge — what git status and @{u} mean).
  • get_branch_push_status looked up refs/remotes/<remote>/<branch> by name.

So a single row could contradict itself. Both cases are reproducible:

A branch fetched but never set to track (git checkout --no-track -b feature origin/feature):

Local Status
before local-only Clean
after ↑0 ↓0 Clean

A branch tracking a differently-named upstream (featureorigin/main):

Local Status
before ↑1 ↓0 Unpublished
after ↑1 ↓0 Unpushed

The fix

Both paths now go through one upstream_oid helper: prefer the configured upstream,
fall back to a remote-tracking ref of the same name.

The fallback is the deliberate part. Pure @{u} semantics would have made the first
case local-only / Unpublished, which is defensible but reports a branch that
demonstrably has somewhere to compare against as having no remote at all. Falling back
keeps the more useful answer while removing the contradiction.

has_unpushed is derived from the same counts, so the summary's "With unpushed" tally
can no longer disagree with the Status column either.

Compatibility

Breaking for anyone parsing the output. The affected shapes are fetched-but-untracked
branches (previously local-only) and branches tracking a differently-named upstream
(previously Unpublished). This moves the table, the summary counts, and the
is_local_only, has_unpushed and status fields of --json.

Every other repository is unaffected — the existing 132 tests pass unchanged. Two
regression tests cover the cases above; both fail on main and pass here.

The `Local` and `Status` columns asked different questions about the same
branch. `get_ahead_behind_and_local_status` used the configured upstream
(`branch.<name>.merge`, what `git status` and `@{u}` mean), while
`get_branch_push_status` looked up `refs/remotes/<remote>/<branch>` by
name. A single row could contradict itself:

  a branch fetched but never set to track
    Local: local-only    Status: Clean

  a branch tracking a differently-named upstream
    Local: up 1          Status: Unpublished

Both now go through one `upstream_oid` helper, which prefers the
configured upstream and falls back to a remote-tracking ref of the same
name. The fallback matters: a branch that was fetched but never tracked
does have somewhere to compare against, and reporting it as local-only
was the more misleading of the two answers.

The rows above now read `up 0 down 0 / Clean` and `up 1 / Unpushed`.
`has_unpushed` is derived from the same counts, so the summary's unpushed
tally can no longer disagree with the status column either.

BREAKING CHANGE: the reported status changes for two branch shapes. A
branch that was fetched but never set to track is no longer reported as
`local-only`, and a branch tracking a differently-named upstream is no
longer reported as `Unpublished`. This affects the table, the summary
counts and the `is_local_only`, `has_unpushed` and `status` fields of the
`--json` output, so anything parsing that output should be rechecked.
@bircni
bircni merged commit f1b8e08 into main Aug 23, 2026
9 checks passed
@bircni
bircni deleted the fix/consistent-upstream-resolution branch August 23, 2026 20:51
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