vscode-pull-request-github
vscode-pull-request-github copied to clipboard
Allow association of local branch with PR
From @segevfiner in https://github.com/microsoft/vscode-pull-request-github/issues/1048#issuecomment-1003578855:
It would have been nice if this extension also allowed to associate an existing branch with a pull request (When you already have it checked out and don't want another pr/7 branch, but sadly this isn't supported as well.
It might also be helpful to go the other way and detach a branch from a PR. So if you don't like the extension going into review mode when entering a certain branch where you created a PR from, you can detach it, and checkout the PR as a separate branch.
It might also be helpful to go the other way and detach a branch from a PR. So if you don't like the extension going into review mode when entering a certain branch where you created a PR from, you can detach it, and checkout the PR as a separate branch.
This is huge pain. I have PR with dozens of comments and it is not possible to make changes in code when you see comments all over editor. I have been using workaround all the time.
Generally it is useful to be able to turn off review mode without checking out branch to main/master. That will be the ultimate solution - it will allow users to use github extension to check things out. See comments but also remove them when they become too invasive
It might also be helpful to go the other way and detach a branch from a PR. So if you don't like the extension going into review mode when entering a certain branch where you created a PR from, you can detach it, and checkout the PR as a separate branch.
This is huge pain. I have PR with dozens of comments and it is not possible to make changes in code when you see comments all over editor. I have been using workaround all the time.
Generally it is useful to be able to turn off review mode without checking out branch to main/master. That will be the ultimate solution - it will allow users to use github extension to check things out. See comments but also remove them when they become too invasive
Check out the workaround here: https://github.com/microsoft/vscode-pull-request-github/issues/1048#issuecomment-1003578855
@wtrocki you can also use the "Collapse all comments" command. There's a setting for it too: githubPullRequests.commentExpandState.
Collapse all commands is really good for this use case. Thank you
I would love an in-extension command to do this, but in the meantime I hacked together an alias that seems to accomplish the same thing (based on the workaround posted in https://github.com/microsoft/vscode-pull-request-github/issues/1048#issuecomment-1003578855).
It's a bit messy but seems to get the job done:
[alias]
assign-pr = "!f() { git config branch.\"$1\".github-pr-owner-number \"$(git remote get-url origin | sed -E \"s#.*github[.]com[/:]([^.]+)([.]git)?#\\1#\" | tr \"/\" \"#\")#$2\"; }; f"
(disclaimer: tested on Linux + macOS, not sure if Windows would work the same here)
It's uses like this (for branch my-cool/branch and PR number 1234):
$ git assign-pr my-cool/branch 1234
Hopefully this is useful for others, at least as long as there isn't an official command to do it.
Thanks @ian-h-chamberlain (and @segevfiner ) for that workaround, super helpful :+1: . I noticed that this was intermittently not working for me, and realized that it was because I was reviewing PRs from new (to me) folks where I didn't already have remotes configured with github-pr-remote = true. Since I already had a gh co alias for the GitHub CLI, I extended it to incorporate the workarounds in this thread and also configure the remote. In the spirit of "hopefully this is useful for others...":
aliases:
co: |
!gh pr checkout $* &&
pr_details=$(gh pr view $* --json url,headRepositoryOwner) &&
current_branch=$(git branch --show-current) &&
# Configure a remote based on the owner of the PR head repo
remote_name=$(echo "$pr_details" | jq -r .headRepositoryOwner.login) &&
remote_url=$(git config "branch.$current_branch.remote") &&
git config "remote.$remote_name.url" "$remote_url" &&
git config "remote.$remote_name.fetch" "+refs/heads/*:refs/remotes/$remote_name/*" &&
git config "remote.$remote_name.github-pr-remote" true &&
# Point the current branch at the new remote and link it to the PR by number
pr_owner_number=$(echo "$pr_details" | jq -r .url | sed -E 's!.*/(.+)/(.+)/pull/(.+)!\1#\2#\3!') &&
git config "branch.$current_branch.github-pr-owner-number" "$pr_owner_number" &&
git config "branch.$current_branch.remote" "$remote_name"
So then I can run gh co 1234 to check out the PR and do all the background stuff to make VS Code see it as a PR.
As of the October release, this should be better. https://github.com/microsoft/vscode-pull-request-github/issues/4464 fixed an issue where we weren't correctly matching PR branches. If you're still seeing local branches not get picked up as PR branches please reply!