-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find PRs using @{push}
#9208
base: trunk
Are you sure you want to change the base?
Find PRs using @{push}
#9208
Conversation
cdc1b5d
to
4226579
Compare
4226579
to
c8a51dd
Compare
Wow this is an oooooold issue. Thank you for your contribution. The details of the original issue look quite involved, so it may take me some time to fully grok and review this. Cheers. |
Hey @Frederick888, can you provide some more context about the end-to-end workflow here? I believe this relates to triangular workflows where there are 2 remotes, one configured for push and one for fetch but I think I'm missing something in my understanding. Here's what I tried locally: Clone my fork and check the remotes:
Configure the triangular workflow:
Create a PR from my fork using the syntax mentioned by Mislav:
Then I expect using
But I anticipated that this PR would fix it:
So what am I misunderstanding? Thanks! |
Ah, perhaps what I'm missing is that when we create the local branch it needs to be checked out from the upstream? Deleting the old branch:
Creating a new branch from
Showing the difference between current release and this PR:
Is this expected behaviour? I'm trying to figure out why it would be important to |
I think the issue here is that when the branch starting point doesn't contain a remote, then the
Which is an issue for https://github.com/cli/cli/pull/9208/files#diff-ccedca01e076cd065987253b366873ca2bee2e28c9d0bc13d50d7b7795c0bf4eR328 I guess the solution to this would be as Mislav suggested:
But that seems out of scope for this, if I understand your goal correctly. Do I understand this correctly @Frederick888? |
It's actually related to both central workflow and triangular. First of all, make sure you've done Central: $ git clone https://github.com/Frederick888/playground.git
Cloning into 'playground'...
remote: Enumerating objects: 164, done.
remote: Counting objects: 100% (68/68), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 164 (delta 40), reused 55 (delta 29), pack-reused 96
Receiving objects: 100% (164/164), 39.82 KiB | 1.99 MiB/s, done.
Resolving deltas: 100% (56/56), done.
$ cd playground
$ git checkout --guess test-diff
branch 'test-diff' set up to track 'origin/test-diff'.
Switched to a new branch 'test-diff'
$ git branch --set-upstream-to origin/master
branch 'test-diff' set up to track 'origin/master'.
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/Frederick888/playground.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "test-diff"]
remote = origin
merge = refs/heads/master
# with my patch
$ gh pr view
test diff Frederick888/playground#7
Draft • Frederick888 wants to merge 4 commits into master from test-diff • less than a minute ago
+8 -1 • - Checks pending
[ ... ]
View this pull request on GitHub: https://github.com/Frederick888/playground/pull/7
# trunk 0df5596512ad44dec74ab3dc07a4e6ea3a7c78fc
$ ~/Programming/Go/gh-cli/bin/gh pr view
no pull requests found for branch "master" Triangular: $ git clone https://github.com/cli/cli.git
Cloning into 'cli'...
remote: Enumerating objects: 54449, done.
remote: Counting objects: 100% (1458/1458), done.
remote: Compressing objects: 100% (817/817), done.
remote: Total 54449 (delta 811), reused 1155 (delta 629), pack-reused 52991
Receiving objects: 100% (54449/54449), 29.40 MiB | 6.75 MiB/s, done.
Resolving deltas: 100% (36967/36967), done.
$ cd cli
$ git remote rename origin upstream
Renaming remote references: 100% (71/71), done.
$ gh repo fork --remote --remote-name origin
! Frederick888/cli already exists
✓ Added remote origin
$ git config branch.trunk.pushremote upstream
$ git config remote.pushdefault origin
$ gh repo set-default cli/cli
✓ Set cli/cli as the default repository for the current directory
$ git fetch --all
$ git checkout --guess find-pr-by-rev-parse-push
branch 'find-pr-by-rev-parse-push' set up to track 'origin/find-pr-by-rev-parse-push'.
Switched to a new branch 'find-pr-by-rev-parse-push'
$ git branch --set-upstream-to upstream/trunk
branch 'find-pr-by-rev-parse-push' set up to track 'upstream/trunk'.
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "upstream"]
url = https://github.com/cli/cli.git
fetch = +refs/heads/*:refs/remotes/upstream/*
gh-resolved = base
[branch "trunk"]
remote = upstream
merge = refs/heads/trunk
pushremote = upstream
[remote "origin"]
url = [email protected]:Frederick888/cli.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote]
pushdefault = origin
[branch "find-pr-by-rev-parse-push"]
remote = upstream
merge = refs/heads/trunk
# with my patch
$ gh pr view | cat
title: Find PRs using `@{push}`
state: OPEN
author: Frederick888
labels: external
assignees:
reviewers: (Requested), williammartin (Requested)
projects: The GitHub CLI (Needs review 🤔)
milestone:
number: 9208
url: https://github.com/cli/cli/pull/9208
additions: 246
deletions: 35
auto-merge: disabled
# trunk 0df5596512ad44dec74ab3dc07a4e6ea3a7c78fc
$ ~/Programming/Go/gh-cli/bin/gh pr view | cat
no pull requests found for branch "trunk" When you check out a new branch, there are some similar things you need to do. But the key is, after pushing the new branch, making sure I've got a super-charged
#575 is a bit more than this issue. What Mislav originally mentioned sounds like something What I'm trying to address here however, is a perfectly valid setup. All the info that we need to determine the target / feature branches are already in gitconfig. Git itself understands the setup already. It's only that
So yeah, you were on the right track 👍 |
c8a51dd
to
16eed48
Compare
@Frederick888, I started extracting issues to describe each of these enhancements in detail e.g. #9363 I'm having trouble understanding the second commit in this series. It seems like the first commit makes it so that:
And after the second commit it makes it so that:
I don't understand what is expected to happen in this last case. I don't understand what this change is intended to protect. Thanks! |
Actually here it uses
Otherwise it uses current branch AFAIU cli/pkg/cmd/factory/default.go Lines 150 to 158 in 0df5596
Since |
16eed48
to
3693b51
Compare
Ah right, I see. Because I'm trying to imagine whether this could have broken any other
I suppose Do you agree? |
Such users are probably of those who always use
Oh yup, good spot! I absolutely should've added it too. b7521e1 and I'll reword the earlier commit too.
Yes I doubt many users actually use this locally. But still it expects 'all branches having the same name on both ends'. So it conveniently falls into the 'otherwise' category. |
f247b33
to
ad62216
Compare
@williammartin Done 😄 (Gonna have to head off soon but let me know if you have other concerns.) |
Under what circumstances could there be a remote branch that has a PR open from it, but The only case I can imagine is that we checkout a new local branch with the same name as a remote branch but that isn't tracking it. Is that a likely scenario? |
Apart from my question above I believe I've captured the value of these changes in the following issues:
|
This comment was marked as spam.
This comment was marked as spam.
Actually since For example, I can even just branch off of a random commit with the name $ git checkout trunk
$ git branch -D find-pr-by-rev-parse-push
$ git show
commit b05bddc210a1e45a25b76f9b320239e4c36f03ee (HEAD -> trunk, upstream/trunk, upstream/HEAD)
Merge: 0d87ddaca 58e619677
Author: Andy Feller <[email protected]>
Date: Mon Jul 29 17:31:20 2024 -0400
Merge pull request #9344 from babakks/9292-add-remove-milestone-option
Add `--remove-milestone` option to `issue edit` and `pr edit`
$ git checkout -b find-pr-by-rev-parse-push
Switched to a new branch 'find-pr-by-rev-parse-push'
$ git rev-parse --abbrev-ref @{push}
origin/find-pr-by-rev-parse-push So the only case where that can happen is when the user didn't fetch the remote branch, e.g. # continue above
$ git branch -d -r origin/find-pr-by-rev-parse-push
Deleted remote-tracking branch origin/find-pr-by-rev-parse-push (was ad62216b0).
$ git rev-parse --abbrev-ref @{push}
@{push}
fatal: ambiguous argument '@{push}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]' |
ad62216
to
c55244e
Compare
Yeh right, so when |
Or the user hasn't pushed.
I agree. Even if a user is dealing with a very active large repo and always only fetches a few branches selectively, it doesn't make too much sense to skip the current remote tracking branch.
Yup and just tested that $ g config push.default simple
$ g checkout --track origin/find-pr-by-rev-parse-push
branch 'find-pr-by-rev-parse-push' set up to track 'origin/find-pr-by-rev-parse-push'.
Switched to a new branch 'find-pr-by-rev-parse-push'
$ g config branch.find-pr-by-rev-parse-push.merge refs/heads/trunk
$ g rev-parse --abbrev-ref @{push}
fatal: cannot resolve 'simple' push to a single destination
$ g push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:trunk
To push to the branch of the same name on the remote, use
git push origin HEAD
To avoid automatically configuring an upstream branch when its name
won't match the local branch, see option 'simple' of branch.autoSetupMerge
in 'git help config'. |
If the user hasn't pushed then there can't be a PR open to This is what I was describing above. The only scenario I can imagine there being a PR to view, a user having |
Yup that's right. Thanks for the clarification. I was talking about that |
Got it! Nice one. Ok, just for your information I am now on vacation, however, I just wanted to finish all the open parts of this discussion. I'd hoped to get this merged before leaving but couldn't due to some unexpected personal circumstances. You shouldn't expect to hear back from me until August 15th or 19th, as I am taking a much needed long break. I'm sorry for the delay. Hopefully I won't have to ask you to remember too much on my return 😅 Thanks for your continued involvement and clarifications, it's been extremely valuable in giving me confidence in getting this change in when I return. |
Ok, just for your information I am now on vacation, however, I just
wanted to finish all the open parts of this discussion. I'd hoped to
get this merged before leaving but couldn't due to some unexpected
personal circumstances. You shouldn't expect to hear back from me
until August 15th or 19th, as I am taking a much needed long break.
I'm sorry for the delay. Hopefully I won't have to ask you to remember
too much on my return 😅
No worries at all! Enjoy your break!
…On 30/7/24 23:36, William Martin wrote:
Got it! Nice one.
Ok, just for your information I am now on vacation, however, I just wanted to finish all the open parts of this discussion. I'd hoped to get this merged before leaving but couldn't due to some unexpected personal circumstances. You shouldn't expect to hear back from me until August 15th or 19th, as I am taking a much needed long break. I'm sorry for the delay. Hopefully I won't have to ask you to remember too much on my return 😅
Thanks for your continued involvement and clarifications, it's been extremely valuable in giving me confidence in getting this change in when I return.
—
Reply to this email directly, view it on GitHub <#9208 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABCMP7Z3SDWBSBC3W35CX5DZO6JHDAVCNFSM6AAAAABJJVOOYWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJYGM3TEMJTG4>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
--
Frederick Zhang
PGP: 8BFB EA5B 4C44 BFAC C8EC 5F93 1F92 8BE6 0D8B C11D
|
c55244e
to
91471ce
Compare
91471ce
to
ba25124
Compare
ba25124
to
40c2ac0
Compare
169a789
to
776ba51
Compare
776ba51
to
fd6c017
Compare
I've just skimmed the conversation, but it looks like all the major questions have been resolved and the fixes documented in linked issues. Are there any remaining barriers to merging this? It would be a huge quality of life improvement for me. Right now I either have to do
(autocomplete doesn't work) or
for the current branch, since my It seems like maybe @williammartin just hasn't checked in since his return 😅 Thanks for all the effort you both put in to creating and documenting this! |
😅 I check it every week, and then I am sad that I've left @Frederick888 hanging for so long.
Purely a matter of prioritising the review. We had a lot of work in the lead up to GitHub universe and some unexpected work after. We're intending to spend a week on getting through these outstanding PRs, I'm hopeful it will happen in the next week or two but I can't commit to that. Did you actually try this branch from source by any change @benknoble ? |
Ah, my apologies! And a second thank you for your diligence.
Makes sense, thank you for your transparency.
No, but I will today. Good suggestion. |
Ok, I confirmed that this branch worked for me using
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some miscellany I noticed while reading the commits.
progress: factory.IOStreams, | ||
pushDefault: func() (string, error) { | ||
return factory.GitClient.Config(context.Background(), "push.default") | ||
}, | ||
progress: factory.IOStreams, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like progress
became unaligned here, causing the diff to be noisier than needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid I didn't quite follow. Could you elaborate a bit? Is it related to my PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean the whitespace between progress:
and factory
changed, which is why the diff looks this way. Does go fmt
realign them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah it was go fmt
that did this in the first place, presumably because it was separated from the lines above.
pkg/cmd/pr/status/status.go
Outdated
if branchConfig.Push != "" { | ||
selector = strings.TrimPrefix(branchConfig.Push, branchConfig.RemoteName+"/") | ||
} else if strings.HasPrefix(branchConfig.MergeRef, "refs/heads/") { | ||
} else if pushDefault, _ := gitClient.Config(context.Background(), "push.default"); (pushDefault == "upstream" || pushDefault == "tracking") && | ||
strings.HasPrefix(branchConfig.MergeRef, "refs/heads/") { | ||
selector = strings.TrimPrefix(branchConfig.MergeRef, "refs/heads/") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is starting to look duplicated with .../finder.go
's parseCurrentBranch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, it will only get worse /s
Jokes aside, IIRC my original plan was to see if I could do a little refactoring when I got to fixing gh pr create
. Now my short memory has got the best of me and I can't remember what issues gh pr create
has exactly hehe. But if anyone's got some pointers in mind, feel free to share, and I can check them out when/if I find some time to get back on this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure: something to follow-up on later. Maybe I'll take a stab sometime
When using a push.default = current central workflow [1], we should use @{push} instead to locate the remote branch. In fact, @{push} covers most cases in push.default = upstream too. The branch.<name>.merge is probably only needed when using RemoteURL and different remote / local branch names. [1] tpope/vim-fugitive#1172 (comment)
When push.default is not 'upstream' / 'tracking' (or 'nothing'), we can expect local and remote branch names to be the same and solely rely on @{push} or RemoteURL. This fixes the wrong error message 'no pull requests found for branch "<target branch>"' when the local branch is not pushed in the push.default = simple / current and upstream = <target branch> setup.
When using a push.default = current triangular workflow, apart from using @{push} to determine the remote branch name, we should also follow the 1. branch.<name>.pushRemote 2. remote.pushDefault 3. branch.<name>.remote ...list to determine which remote Git pushes to.
fd6c017
to
285a5df
Compare
f9a1329f
Find PRs using @{push}
a049eade
Only find PRs w/ branch.<name>.merge if push.default = upstream/tracking
285a5df0
Find push remote using branch.<name>.pushRemote and remote.pushDefault
This fixes things like
gh pr view
in apush.default = simple / current
+ upstream pointing to target branch.It does not fix the issues with
gh pr create
.Related to: #575.