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

Allow pasting (cherry picking) commits onto branch from branches view #3275

Open
jesseduffield opened this issue Jan 28, 2024 · 6 comments
Open
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@jesseduffield
Copy link
Owner

jesseduffield commented Jan 28, 2024

Is your feature request related to a problem? Please describe.
Currently, in order to cherry-pick commits, you need to:

  1. select the commits
  2. checkout the destination branch
  3. paste the commits by pressing 'v' in the local branches view

In github desktop you instead select select the commits and right click to cherry pick, then in a popup you specify the destination branch. That branch is then checked out (with any working tree changes stashed if required) and the commits are cherry picked. You then remain on the destination branch.

image

image

Describe the solution you'd like
Given that we're not using the 'V' keybinding for anything else in the commits view, I think we should support pressing 'V' directly on the branch. This will:

  • check if changes need to be stashed, and if so, prompt the user whether they want to stash the changes
  • check out the branch
  • paste the commits

We should also support this if you're in the sub-commits view, viewing the commits of a local branch.

This slightly reduces the amount of work required in cherry picking commits from one branch to another.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

@jesseduffield jesseduffield added enhancement New feature or request good first issue Good for newcomers labels Jan 28, 2024
@nhAnik
Copy link

nhAnik commented Jan 29, 2024

Hi @jesseduffield , I would like to give it a try. Would you please assign me?

@jesseduffield
Copy link
Owner Author

Sure thing @nhAnik, let me know if you need any pointers.

For starters you'll want to add the keybinding to pkg/gui/controllers/branches_controller.go and internally you'll want to check out the (if it's not already checked out) and then call self.c.Helpers().CherryPick.Paste()

@nhAnik
Copy link

nhAnik commented Jan 29, 2024

Thanks!
Skimming through the codes and dev docs. I will ask you if I need any help.

@stefanhaller
Copy link
Collaborator

I wonder if the proposed UX is the best one for this feature. Personally I would find it somewhat unexpected that a branch is checked out automatically when I invoke this command.

With the new 2.44 version of git we could consider a different approach:

  • check if the destination branch is checked out in any worktree, if so, switch to it (after prompting the user, probably) and proceed normally
  • otherwise, use git replay --advance to cherry-pick the commits onto the destination branch without checking it out. See here for more information.

The downside is that we'd have to make a version-check and disable the command for git versions older than 2.44; also, the replay command is marked as experimental in the documentation, so I'm not sure we already want to rely on it.

Any thoughts @jesseduffield?

@jesseduffield
Copy link
Owner Author

I'm in favour for a feature for git replay that's marked as experimental in tandem with the underlying git feature.

@stefanhaller
Copy link
Collaborator

OK cool. @nhAnik I haven't looked at the code of #3288 at all to tell how much of it was done in vain. Sorry for not mentioning this earlier!

BTW, one downside of the git reply approach is that if there's a conflict, the command simply fails with an error code. The user will then have to check out the branch and try pasting there again to see what the conflicts are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants