fix(gitinfo)!: resolve the upstream the same way for both columns - #57
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Breaking: this changes the reported status for two branch shapes. See Compatibility below.
The bug
The
LocalandStatuscolumns asked different questions about the same branch.get_ahead_behind_and_local_statusused the configured upstream(
branch.<name>.merge— whatgit statusand@{u}mean).get_branch_push_statuslooked uprefs/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-onlyClean↑0 ↓0CleanA branch tracking a differently-named upstream (
feature→origin/main):↑1 ↓0Unpublished↑1 ↓0UnpushedThe fix
Both paths now go through one
upstream_oidhelper: 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 firstcase
local-only/Unpublished, which is defensible but reports a branch thatdemonstrably has somewhere to compare against as having no remote at all. Falling back
keeps the more useful answer while removing the contradiction.
has_unpushedis derived from the same counts, so the summary's "With unpushed" tallycan 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 theis_local_only,has_unpushedandstatusfields of--json.Every other repository is unaffected — the existing 132 tests pass unchanged. Two
regression tests cover the cases above; both fail on
mainand pass here.