[Proposal]: Checkout PR command
Opened this issue · 6 comments
Problem Description
Currently, if you need to check out a branch from a PR to test it locally, you need to figure out if it is on a fork or a branch that exists in the repo. Then, if it is a fork, you need to add a remote to that fork and then checkout the relevant branch.
Proposed solution
Add a command that would operate something like git checkout-pr <pr_url>
, and figure out whether or not the branch referred to in the url is on a fork or the main repo. It would set up any necessary remote and then checkout the appropriate branch. It is also worth considering adding a "cleanup" command or option here, that removes the remote and deletes the branch once you are done.
So basically it is a command that can check out according to PR. Just want to ask you several questions to help me better understand the feature:
Take git-utils as an example: I downloaded the Leo6Leo/git-utls.git on my Mac.
Scenario 1:
Leo@Leo's MacBook: cd git-utls
Leo@Leo's MacBook: git checkout-pr https://github.com/Cali0707/git-utils/pull/22
What will the command do?
Scenario 2:
Leo@Leo's MacBook: cd git-utls
Leo@Leo's MacBook: git checkout-pr https://github.com/Leo6Leo/git-utils/pull/1
(Assume Leo6Leo#1 exist)
What will the command do?
Scenario 3:
Leo@Leo's MacBook: cd git-utls
Leo@Leo's MacBook: git checkout-pr https://github.com/Leo6Leo/eventing
What will the command do?
Scenario 4:
Leo@Leo's MacBook: cd git-utls
Leo@Leo's MacBook: git checkout-pr https://github.com/knative/eventing
What will the command do?
@Leo6Leo I imagine that:
Scenario 1: this would go and see if pull/22 was from a fork or not. If it was from a fork, it would add the appropriate remote and then create a new branch from that remote.
Scenario 2: this would again go and see if pull/1 was from a fork or not. Also, if Leo6Leo/git-utils is not a remote on the current repo, it would create a remote to it if pull/1 was not from a fork.
Scenarios 3 & 4: no pull URL was provided, so it will tell them to have an appropriate PR url
WDYT?
Wdym "if pull/22 was from a fork or not"? If it is from a fork, do you mean PR#22 is a PR in Leo6Leo/git-util?
Let me make this more clear by having some more cases:
Case 1
Cali0707 created the upstream repo Cali0707/git-utils, and Leo6Leo forked it and has Leo6Leo/git-utils
And currently, Leo6Leo is running git-utils commands in ~/Downloads/git-utils, and this is Leo6Leo/git-utils.git
The PR links I used in the text below are valid.
Scenario 1
Leo6Leo try to git checkout-pr a pr from cali0707/git-utils because he needs to review one of Cali's PR.
This PR is not from a fork, and as expected, it should clone the Cali0707/git-utils repo, and checkout to add-make-pr-command
branch.
Scenario 2
Leo6Leo try to git checkout-pr a pr from Leo6Leo/utils because he needs to review one of his own PR.
This PR is from a fork, and as expected, it should just directly checkout to leo/test
branch.
Scenario 3
Cali0707 try to git checkout-pr a pr from Cali0707/git-utils because he needs to review one of his own PR. This PR is by Leo6Leo, and Leo6Leo is trying to merge Leo6Leo/git-util.git leo/test
branch to Cali0707/gitutil.git main
.
This PR is not from a fork, and as expected, it should clone the Cali0707/git-utils repo, and checkout to add-make-pr-command
branch.
...... A bit sleepy rn, let's discuss this in person cali 🥱 @Cali0707