Skip to content
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

[Proposal]: Checkout PR command #27

Open
Cali0707 opened this issue Jul 17, 2023 · 6 comments
Open

[Proposal]: Checkout PR command #27

Cali0707 opened this issue Jul 17, 2023 · 6 comments

Comments

@Cali0707
Copy link
Owner

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.

@Cali0707
Copy link
Owner Author

Thoughts @Leo6Leo ?

@Cali0707 Cali0707 changed the title [Proposal]: Chekcout PR command [Proposal]: Checkout PR command Jul 17, 2023
@Leo6Leo
Copy link
Collaborator

Leo6Leo commented Jul 18, 2023

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
Copy link
Collaborator

Leo6Leo commented Jul 18, 2023

@Cali0707

@Cali0707
Copy link
Owner Author

Cali0707 commented Jul 22, 2023

@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?

@Leo6Leo
Copy link
Collaborator

Leo6Leo commented Jul 23, 2023

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

@Cali0707
Copy link
Owner Author

Cali0707 commented Aug 1, 2023

Per conversation with @Leo6Leo :

  1. Find the remote for the PR branch
  2. Find the branch name for the PR
  3. Add remote if needed
  4. Checkout remote/branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants