You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repository.Current() ignores gh-resolved and selects the wrong repo when a remote is named "github" #286
repository.Current() selects a repository by ranking remotes on their name alone, and never consults the gh-resolved git config value that gh repo set-default writes — even though Remotes() reads that value into Remote.Resolved immediately beforehand. In a repository where the fork is on a remote named github and the parent is on origin, Current() returns the fork, contradicting both the user's explicit gh repo set-default choice and gh's own answer for the same repository.
Current behaviour
Remotes() (internal/git/remote.go:43) calls setResolvedRemotes(remotes) at line 49, populating Remote.Resolved (field at line 18, set at line 144) from git config --get-regexp ^remote\..*\.gh-resolved$. Line 50 then sorts by remoteNameSortScore (line 30): upstream=3, github=2, origin=1, everything else 0. Current() (pkg/repository/repository.go:119) takes filteredRemotes[0] at line 152. Resolved appears zero times in the body of Current().
Expected parent-org/example. gh repo set-default --view in the same directory correctly prints parent-org/example.
Removing the gh-resolved setting produces identical output, confirming the value has no effect on the result. GH_REPO=parent-org/example does override correctly.
Expected behaviour
Current() should prefer a remote whose Resolved value is set, ahead of the name-based ranking. cli/cli already has exactly this in context/remote.go:51:
go-gh populates the same field but has no equivalent, so the two libraries disagree about the same repository.
The gh-resolved support was added in 9cb500d ("Add support for selected default remote", 2021-09-27), which suggests wiring it into Current() was intended and simply missed.
Impact
Consumers silently operate on the wrong repository, with no error. Surfaced via gh-dash, whose smart filtering injects repo:<owner>/<name> from Current() and so shows an empty PR list for a fork with no PRs.
Environment
go-gh v2.13.0 (and current trunk — code unchanged)
gh 2.96.0, go 1.25.12, Linux
Prior search
Searched go-gh and cli/cli issues and PRs, all states, for gh-resolved, repository.Current, remote sorting/precedence, and fork-vs-upstream selection. Closest existing items are #274 (SSH-alias translation) and cli/cli#13027 (proxy URLs failing host detection); neither covers this.
Activity