Interactive rebase with in-editor TODO edit#2370
Interactive rebase with in-editor TODO edit#2370jesseduffield merged 9 commits intojesseduffield:masterfrom
Conversation
2a5591b to
52e7f3b
Compare
52e7f3b to
5191e04
Compare
|
@AzraelSec Thanks for raising a PR. Currently this PR has us opening up a TODO file in the editor but what I want instead is to start an interactive rebase within lazygit, as if we had hit If you have a use case for viewing the TODO file in say vim and editing that yourself, we should have a separate keybinding for that which you can use inside the commits panel when we're in the middle of an interactive rebase. Let me know if you have any questions :) |
Ouch, I'm sorry @jesseduffield I clearly misunderstood what the commenters were talking about while discussing the issue! Okay, I got what you mean and it ultimately makes sense 😅 I'll try to implement this feature with the UX you expect 👍🏻 For what regards the editing of the TODO file using an external editor (as I'd prefer to do), would it make sense to you to integrate it? Do you prefer me to close this PR and open a separate issue where we can discuss it before opening a new PR? Thank you! 🙏🏻 |
|
I'm happy for us to continue using this PR and to just leave out functionality around editing the TODO file in an editor :) |
|
the desired feature can be achieved via a custom command: |
5191e04 to
282f8bb
Compare
|
@joihn I've been inactive for a while, but yesterday I should have reached a good implementation of this feature. So let me rebase my branch and see what @jesseduffield thinks is the best option. It would take me just some hours 👍🏻 |
282f8bb to
51ec8c6
Compare
|
@jesseduffield, the PR should now introduce the discussed feature as you were expecting. Let me know if it satisfies your requirements 👍🏻 Thanks! |
|
Uffizzi Preview |
jesseduffield
left a comment
There was a problem hiding this comment.
Nice work, I've left some comments.
The alternative approach to this would be to obtain the final todo file before we start the rebase. That would require us to do more work upfront in finding out which commits need to be rebased, but it would simplify the interface with the daemon. Given our goal of sticking as close to the git CLI's way of doing things as possible, I think the approach this PR takes is the right one. That is, if we did try to work out the commits to rebase ourselves, we'd risk diverging from git's natural behaviour.
| map[string]string{ | ||
| "checkedOutBranch": checkedOutBranch, | ||
| "selectedBranch": ref, | ||
| menuItems := []*types.MenuItem{ |
There was a problem hiding this comment.
We still want to tell the user that we're rebasing from checkedOutBranch to ref. So I'm thinking:
Title: Rebase '{{checkedOutBranch}}' onto '{{ref}}'
Item 1: s: Simple rebase
Item 2: i: Interactive rebase
And I'd add a tooltip for item 2 saying 'Begin an interactive rebase with a break at the start, so you can update the TODO commits before continuing'
pkg/commands/git_commands/rebase.go
Outdated
| // we tell git to run lazygit to edit the todo list, and we pass the client | ||
| // lazygit a todo string to write to the todo file | ||
| func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseShaOrRoot string, todoLines []TodoLine, overrideEditor bool) oscommands.ICmdObj { | ||
| func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseShaOrRoot string, todoLines []TodoLine, overrideEditor bool, prepend bool) oscommands.ICmdObj { |
There was a problem hiding this comment.
We've got quite a few positional arguments here now. Let's create a PrepareInteractiveRebaseCommandOpts struct which can be passed as the single argument to this method.
| RebaseTODOEnvKey string = "LAZYGIT_REBASE_TODO" | ||
| DaemonKindEnvKey string = "LAZYGIT_DAEMON_KIND" | ||
| RebaseTODOEnvKey string = "LAZYGIT_REBASE_TODO" | ||
| PrependLinesEnvKey string = "LAZYGIT_PREPEND_LINES" |
There was a problem hiding this comment.
I'm not sure I'm following this code right, can you confirm:
When we want to do an interactive rebase (with a break) onto a ref, we pass LAZYGIT_REBASE_TODO="break" and LAZYGIT_PREPEND_LINES=true and then when the lazygit daemon is invoked to update the git-rebase-todo file, that file will already have all the commits from the original branch that we're about to rebase onto the ref, and we'll then prepend the break action onto the existing TODO lines so that in lazygit we can modify the remaining TODO lines. Is that right?
If that's correct, we should have a comment explaining what we're doing because it's not immediately obvious from looking at the code. We can put that comment above the PrependLinesEnvKey const
There was a problem hiding this comment.
Yes, your assumption is correct. I'll introduce a comment as you suggested to give more context on the reasons behind this implementation.
|
Also @AzraelSec could you add an integration test for when the user chooses the interactive rebase option? |
I agree that crafting a todo file ourselves is not a good idea, and we should let git do the work; it knows better how to do that. For example, when people have In fact, we have this problem already for the cases where we do craft our own todo file, e.g. when you press "e" on a commit. I'm working on changing these to let git produce the todo file, using a very similar mechanism like this PR does. This way it will also be able to support |
4ae485b to
8cfa431
Compare
|
@jesseduffield I should have applied all the changes requested 👍🏻 I used the logic you and @stefanhaller were discussing precisely because having a list of commits consistent with the canonical git behaviour ahead of time is challenging. We are configuring our tool to perform some actions during the rebase in "headless" mode: the requester instance of lazygit needs to tell the second one what to do with the In the future, it would be great to think about a more complex way of encoding the commands we want the daemon to execute, a complete parsing mechanism of the default |
|
This is great, I'm looking forward to having this feature; I didn't realize at first how often I would find it useful (I was a bit skeptical about it's usefulness when it was initially proposed 😄). However, I'd like to point out a potential problem: at the moment, lazygit works on the assumption that the number of lines in the I'm working on a PR to fix this, I hope to have it ready by the end of the week at the latest; just pointing this out because the new command in this PR will expose people to this situation more often, so we might want to hold off merging this until the fix is in. |
|
@stefanhaller don't want to bother or rush you, but do you have any updates on this? I'd like to move this PR forward at some point. Thanks! 🙏🏻 |
|
I have a branch that has been ready for almost a week now; I didn't make a PR yet because I didn't want to swamp Jesse with too many review requests. Looks like he's too busy to review things right now, and I have a few other PRs open that I first want to get merged before I open new ones. |
|
I see; no problem, thank you. Could you please keep this PR up-to-date on this? Thanks! |
|
@stefanhaller if you've got that branch available feel free to raise it and I can give it a review, if it's a blocker for this PR. I'm happy to do the extra work of rebasing my refactor PR if it means we can keep things moving now |
|
The PR is here: #2547 |
|
@AzraelSec There are several files in your PR that have formatting problems (that's why the linter check failed). Can you please run |
757c1aa to
c22c77c
Compare
@stefanhaller I've fixed the code and executed all the actions locally to be sure they pass; everything should be fine now. Thank you for the heads-up! 😄 |
…f confirm the previous popup
`PrepareInteractiveRebaseCommand` function
a07f0d7 to
6b85134
Compare
|
I've pushed a small change to the copy and I've rebased on master. Once CI passes, I'll merge :) |
…on 'Sentence case')
6b85134 to
8f1f712
Compare
|
As I started to use this feature more, I realized that I always have to switch focus to the commits panel when picking "interactive". It would be nice if it did this for me automatically. But I suppose we can also add this as a followup if you'd rather merge now. |
|
@stefanhaller I was just thinking about that myself. A couple times I've switched focus on behalf of the user and ended up deciding against it but in this case the only reason you're taking the interactive approach is so that you can mess around in the commits view so I reckon we switch focus here (in this PR). A simple |
|
@stefanhaller @jesseduffield good point! Yes, sure, that makes sense. Let me change it, I'll be back in minutes. |
|
@stefanhaller @jesseduffield I should have correctly moved the focus after selecting an interactive rebase 👍🏻 I've also changed the integration test to include the focus check to avoid any unintentional change in the future. |
|
Thanks for making this @AzraelSec ! |
|
@jesseduffield @stefanhaller thanks to you for your feedback! Hope to continue contributing to lazygit in the future 💪 |
|
Looking forward to it |
This PR closes issue Suggestion: shortcut to interactive rebase on top of selected commit/branch #733. In particular, it adds the possibility to perform interactive rebases after editing the TODO file using an external editor.
I've updated the already existing integration tests to make them pass, but it would be a good idea to add one for this specific feature later on. I've tried to include it inside this same branch but I couldn't easily handle the interaction with the external editor.
Disclamer: first contribution, hope I made it well but forgive any error I could have made 🙏🏻
go run scripts/cheatsheet/main.go generate)docs/Config.md) have been updated if necessary