vscode-pull-request-github icon indicating copy to clipboard operation
vscode-pull-request-github copied to clipboard

Allow association of local branch with PR

Open alexr00 opened this issue 3 years ago • 6 comments

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.

alexr00 avatar Jan 03 '22 14:01 alexr00

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.

segevfiner avatar Jan 03 '22 14:01 segevfiner

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

wtrocki avatar Jan 20 '22 14:01 wtrocki

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

segevfiner avatar Jan 20 '22 16:01 segevfiner

@wtrocki you can also use the "Collapse all comments" command. There's a setting for it too: githubPullRequests.commentExpandState.

alexr00 avatar Jan 21 '22 09:01 alexr00

Collapse all commands is really good for this use case. Thank you

wtrocki avatar Jan 21 '22 09:01 wtrocki

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.

ian-h-chamberlain avatar Jun 03 '22 20:06 ian-h-chamberlain

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.

ajkerrigan avatar Aug 04 '23 16:08 ajkerrigan

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!

alexr00 avatar Dec 15 '23 15:12 alexr00