KEMBAR78
`pr view` and `pr status` should work with `push.default = simple` even if the branch is set to merge from a different remote branch · Issue #9374 · cli/cli · GitHub
Skip to content

pr view and pr status should work with push.default = simple even if the branch is set to merge from a different remote branch #9374

@williammartin

Description

@williammartin

Description

#9363 suggests that when the @{push} revision syntax works, we should use that to resolve the correct remote branch for invocations of gh pr view and gh pr status when we expect the PR to be found from the currently checked out local branch.

However, when push.default = simple (the default) and a branch config's merge entry has a different name than the local branch, @{push} will not resolve. Fortunately, in the case of push.default = simple, we should expect that the remote push branch has the same name as the local branch.

Consider the following workflow:

We clone our repo, and create a new branch that is tracking main for merges:

➜ gh repo clone williammartin-test-org/test-repo
Cloning into 'test-repo'...
remote: Enumerating objects: 160, done.
remote: Counting objects: 100% (90/90), done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 160 (delta 35), reused 54 (delta 14), pack-reused 70
Receiving objects: 100% (160/160), 25.26 KiB | 5.05 MiB/s, done.
Resolving deltas: 100% (50/50), done.

➜ cd test-repo

➜ git checkout -b push-default-simple origin/main
branch 'push-default-simple' set up to track 'origin/main'.
Switched to a new branch 'push-default-simple'

➜ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://github.com/williammartin-test-org/test-repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
        remote = origin
        merge = refs/heads/main
[branch "push-default-simple"]
        remote = origin
        merge = refs/heads/main

So we create new a commit on the branch, and a new pull request:

➜ git commit --allow-empty -m "push-default-simple" && git push origin push-default-simple
[push-default-simple 75f49e6] push-default-simple
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 195 bytes | 195.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'push-default-simple' on GitHub by visiting:
remote:      https://github.com/williammartin-test-org/test-repo/pull/new/push-default-simple
remote:
To https://github.com/williammartin-test-org/test-repo.git
 * [new branch]      push-default-simple -> push-default-simple

➜ gh pr create -H push-default-simple --title push-default-simple --body push-default-simple

Creating pull request for push-default-simple into main in williammartin-test-org/test-repo

https://github.com/williammartin-test-org/test-repo/pull/51

However when we try to view our newly created PR it fails because it is trying to find a PR from main since that is the current merge entry in the branch config:

➜  test-repo git:(push-default-simple) gh pr view
no pull requests found for branch "main"

Unfortunately, @{push} doesn't work because the merge entry for the branch config has a different branch name:

➜ git rev-parse --abbrev-ref push-default-simple@{push}
fatal: cannot resolve 'simple' push to a single destination

Proposed Solution

Fortunately we know that if our push.default = simple (meaning local and remote branch have the same name) then we should just use that branch name to find the PR, rather than using the merge entry in the branch config.

Additional context

This is already implemented by #9208, I'm just capturing the specific enhancement separately as it was kind of hard for me to understand as someone that's never used these features before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-prrelating to the gh pr command

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions