Repository navigation
Document which remote is used for :owner, :repo placeholders #2657
Description
Activity
- changed the title
[-]Uses wrong origin for for api :repo (picks upstream instead of origin)[/-][+]Uses wrong origin for for api :repo and :owner (picks upstream instead of origin)[/+]on Dec 19, 2020 - added 4 commits that reference this issue
on Dec 20, 2020 Hi, thank you for reporting and proposing a fix!
The current sorting logic is working as intended: the
upstreamremote has priority, thengithub, thenorigin, and then any other remote (in the order they appeared ingit remote -voutput).The current logic is designed to address the "triangular workflow" with git where the upstream repo is pointed to by the
upstreamremote, and your fork has theoriginremote, from which you submit PRs toupstream.Obviously, this workflow doesn't match everyone's needs and expectations. Some people prefer to name their remotes the other way around. For interactive commands such as
gh pr create, we ask users to select which is their "base" remote. But for scripting commands such asgh api, we don't ask for the base remote, and instead default to the first one found in the order ofupstream,github,origin, and*.We will be considering adding flags to select the git remote which is used for a command. But in the meantime, if you need control over which remote gets used, please do not use
:ownerand:repoplaceholders ingh apicommand, but supply the values yourself.Thanks for the detailed update. I understand the sort order makes sense for the "triangular workflow" when working with all the other commands except API. But I cannot think of a case where running API commands against upstream by default would make sense. To me that is surprising and undocumented behaviour.
In your example, I would not have full API access to run command against
upstreamsince I am not the owner of the repo.Can you provide an expected use case for the "triangular workflow" where
gh apiwould want to targetupsteamorgithuboverorigin? Otherwise with the current behaviour, anyone using the "triangular workflow" will be unable to usegh apion their own repo (perhaps that is the expected use-case?).Maybe we can update the docs for the
gh apicommand to make this behaviour clear along with the suggested use-case?Finally, I agree it would be nice if there was a way as you suggested to customize this order, or at least override for the
gh apicommand. The:ownerand:repoplaceholders are very convenient since otherwise one must invent ways to "discover" them which requires extra tooling.Can you provide an expected use case for the "triangular workflow" where
gh apiwould want to targetupstreamorgithuboverorigin?Yes: for example querying issues, PRs, or Releases for the project. The
upstreamrepository will likely contain all that information, while my fork underoriginwill usually have none of that.But you are right that defaulting to a single remote will not work for absolutely everyone. We've had a lot of backlash whenever we picked a new default remote for
gh pr create, for example. In the end, we decided against having defaults and prompt users every time to which remote they wanted to push.Maybe we can update the docs for the
gh apicommand to make this behaviour clear along with the suggested use-case?Absolutely! I've reopened an issue to track that.
The
:ownerand:repoplaceholders are very convenient since otherwise one must invent ways to "discover" them which requires extra tooling.Agreed. Would it be helpful to have a utility command in
ghthat allows you to name a remote and it outputs theowner/repopair for that remote? Then one could do:gh api "repos/$(gh owner-repo origin)/issues"- changed the title
[-]Uses wrong origin for for api :repo and :owner (picks upstream instead of origin)[/-][+]Document which remote is used for `:owner`, `:repo` placeholders[/+]on Jan 11, 2021 But you are right that defaulting to a single remote will not work for absolutely everyone. We've had a lot of backlash whenever we picked a new default remote for gh pr create, for example. In the end, we decided against having defaults and prompt users every time to which remote they wanted to push.
Absolutely understandable. I think having a way to configure this behaviour would go a long way. Personally I find the prompt a bit disruptive. Does git config allow external tools to piggyback on it's config? That way one could use
git configto set gh cli options both for the user and per-repo. This way, one could set the default remote to use for PRs, API reqs, etc.Agreed. Would it be helpful to have a utility command in gh that allows you to name a remote and it outputs the owner/repo pair for that remote?
This could be handy. Even if we had a config to set defaults, this sub command would allow users to make workflows that hit different repos via
--repo $(gh owner-repo origin). Maybe alias could be (ab)used here, to make commands likegh api-origin.Thinking about this more, I think an underlying cause is how
upstreamis often used to mean two different things (or sometimes both at the same time): (A) upstream is the repo you are contributing code back to, origin is otherwise an unused fork; (B) upstream is the repo you pull updates from, origin is what is actually used. (A) is what we often see for OSS projects, but (B) is common for internal projects (that may start from some existing base or template or need add customization).Reacted by Mislav MarohnićI think this conversation has produced a few useful enhancements that
ghcould benefit from, so
I'm going to label this issue as such.I think I'd like remotes to be more of a first class concern to
ghwith support in eitherghor
git's configuration for denoting the roles various remotes should have for a given user.Reacted by Evan Sosenko, Max Falk and RouseSzReacted by Evan Sosenko and RouseSz- addedenhancementa request to improve CLIa request to improve CLIcoreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributors
on Jan 28, 2021
Describe the bug
When a repo has two remotes,
originandupstream, thegh apicommand will useupstreamfor:repoinstead oforigin. This mean API requests are sent to the wrong repo! Also affects:owner.Steps to reproduce the behavior
Expected
Actual
Perhaps wrong sort on the order here?
cli/context/remote.go
Lines 37 to 48 in 72eeae9