Skip to content

Document which remote is used for :owner, :repo placeholders #2657

@razor-x

Description

@razor-x

Describe the bug

When a repo has two remotes, origin and upstream, the gh api command will use upstream for :repo instead of origin. This mean API requests are sent to the wrong repo! Also affects :owner.

gh version 1.4.0 (2020-12-15)

Steps to reproduce the behavior

mkdir test-bad-remote
cd test-bad-remote
git init
g remote add origin git@github.com:cli/cli.git
g remote add upstream  git@github.com:cli/oauth.git
gh api repos/:owner/:repo

Expected

{
  "full_name": "cli/cli"
   ...
}

Actual

{
  "full_name": "cli/oauth"
   ...
}

Perhaps wrong sort on the order here?

cli/context/remote.go

Lines 37 to 48 in 72eeae9

func remoteNameSortScore(name string) int {
switch strings.ToLower(name) {
case "upstream":
return 3
case "github":
return 2
case "origin":
return 1
default:
return 0
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsdocsenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions