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

Checkout pull-request without resetting existing branch #519

Closed

Conversation

DamienCassou
Copy link
Contributor

Closes #518.


This is work-in-progress. I'm opening the PR because I'm not sure I
understand everything and require early feedback. Can you please
advice me?

@DamienCassou DamienCassou marked this pull request as draft September 14, 2022 19:55
@DamienCassou
Copy link
Contributor Author

/CC @tarsius I would appreciate early feedback. Thank you.

@tarsius tarsius changed the title WIP Checkout pull-request without resetting existing branch Sep 15, 2022
@DamienCassou
Copy link
Contributor Author

I've seen you have pushed some cleanup fixes, thank you. Do you know if this is the right direction? Is there something I should work on?

@DamienCassou
Copy link
Contributor Author

Just a though: if b l in magit would add the PR id to the branch name, we wouldn't need b f.

@DamienCassou
Copy link
Contributor Author

I've been using that PR for over a month now and am very happy with the result.

(let ((magit-inhibit-refresh t))
(forge-branch-pullreq pullreq))))))
(forge-branch-pullreq pullreq))
branch))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not certain I follow everything here, but this looks like it will ask twice if you select 'ask (once “Reset %s?”, and then “A branch named "%s" already exists … [r][c][a]” when forge-branch-pullreq is called) and if you select t, then it will still ask once in forge-branch-pullreq, no?

I think this change would be better made a bit deeper, in forge--pullreq-branch-select, because it’ll improve both forge-checkout-pullreq and forge-checkout-worktree (I use the latter mostly).

Then an option could be added to the existing prompt to support checking out the existing branch [u]se existing "%s" branch (a result you can’t currently get, and in your change is only possible unilaterally).

And finally, the defcustom would have options for every case, like 'reset, 'create, 'use, 'abort, and nil (for “ask”). Leaving nil as the default so that the behavior doesn’t change for users who don’t set it.

@@ -50,6 +50,14 @@ Takes the pull-request as only argument and must return a directory."
:group 'forge
:type 'function)

(defcustom forge-checkout-reset-existing-branch nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the current state of this branch that the default here should be t, as that will preserve the existing behavior. nil is “dangerous” in that it gives the user an existing branch without letting them know (and without them choosing that behavior). With the existing code they would only be handed a branch without question if it were newly-created.

(With my suggestions below, nil would be the correct default.)

@DamienCassou
Copy link
Contributor Author

Thank you very much for your feedback. This PR is only a draft to get some help from @tarsius as I don't understand everything the code is doing.

I've been using the code for months now and am very happy about it.

@tarsius
Copy link
Member

tarsius commented Nov 30, 2022

I'm sorry this has continuously been falling through the cracks. I'll try to have another look soon.

@tarsius tarsius closed this in 3d2fafd Dec 8, 2022
@tarsius
Copy link
Member

tarsius commented Dec 8, 2022

I've merged something.

The more I looked at the clearer it became that an existing branch should just be checked out and that offering the option to reset would lead down a rabbit whole. More details in the commit message.

tarsius added a commit that referenced this pull request Dec 8, 2022
If the local branch that represents a pull-request already exists,
then always use it as-is.  Never try to update it to point at the same
commit as the pull-request as it exists on a remote.  Trying to do the
latter would be a futile endeavor.  If the local and remote branches
have diverged, then the user is expected to reconcile that fact using
appropriate general purpose Magit command, which performs the action
that they feel is right in each particular case.  Since we configure
the fork remote and branch relationships as appropriate, it should be
easy enough to reason about diverging history.

We cannot know how to dwim if the user checks out / "creates" an
existing branch, which is/isn't the current branch in this/another
worktree, with history diverging on both sides / new commits only on
the local/remote side; without/with any staged and/or unstaged
changes; when we can/cannot use the same name as on the remote; the
fallback branch "pr-N" does/doesn't exist; the pull-request comes from
the upstream / a fork; pr metadata is/isn't already set up, and so on.

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

Successfully merging this pull request may close these issues.

Checkout a PR branch without resetting anything
3 participants