-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Improve editing a commit #4090
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
Improve editing a commit #4090
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
jesseduffield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I noticed some of these shortcomings last week when I was trying to make a video explaining how stacked branches work in lazygit. One other benefit of this that you don't mention in your description is that you can now edit the tip of another branch, then add a brand new commit, and it'll become the new tip of the branch.
So it seems like now you can do everything from the top branch in the stack without needing to check anything else out, except for pushing branches. Not directly relevant to this PR: but what do you think about allowing users to push the top branch and have ancestor branches in the stack also push at the same time? Seems like the missing piece of the puzzle to me
| }) | ||
| if ok1 && ok2 { | ||
| self.context().SetSelectionRangeAndMode(newSelectedIdx, newRangeStartIdx, selectionRangeAndMode.mode) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we can't find the original start/end, we should exit the range select mode (assuming it's actually possible to end up in that situation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to end up in that situation, I was just being extra defensive. But I wouldn't feel good about adding logic that I don't know how to write a test for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries
I thought about that, but wasn't sure if this should happen by default when pressing shift-P, or be a separate interaction. If we ever add that sync menu that you suggested in #2755, it could go in there.
Not the only one, another one is pulling a stack if a coworker has rebased it. See the discussion in #2755 |
The test demonstrates that the "update-ref" todo after the selected commit is missing, which means when we amend the commit it'll break the stack.
Auto-amending is a little-known feature of git that is very convenient once you know it: whenever you stop at a commit marked with `edit` in an interactive rebase, you can make changes and stage them, and when you continue the rebase they automatically get amended to the commit you had stopped at. This is so convenient because making changes to a commit is one of the main reasons why you edit a commit. Unfortunately this currently doesn't work in lazygit because we don't actually use `edit` to stop at the first commit (instead, we add a `break` todo after it, which doesn't have the auto-amend functionality). We'll improve this later in this branch.
This is very similar to edit_range_select_outside_rebase.go, except that it selects commits right after, and including, a merge commit. This test already works correctly. The reason we add it is that we are going to have two different implementations of the `e` command depending on whether the last selected commit is a merge commit, and we want to make sure they both work with a range selection.
…ebase We will need this because under some conditions we are going to use this function to edit a range of commits, and we can't set merge commits to "edit". This corresponds to the code in startInteractiveRebaseWithEdit which has similar logic. It is a bit unfortunate that we will have these two different ways of setting todos to edit: startInteractiveRebaseWithEdit does it after stopping in the rebase, in the Then function of its refresh, but InteractiveRebase does it in the daemon with a ChangeTodoActionsInstruction. It still makes sense though, given how InteractiveRebase works. This not only affects "edit", but also "drop", "fixup", and "squash". Previously, when trying to use these for a range selection that includes a merge commit, they would fail with the cryptic error message "Some todos not found in git-rebase-todo"; now they simply exclude the merge commit. I'm not sure if one is better or worse than the other, and we should probably simply disable the commands when a merge commit is selected, but that's out of scope in this PR.
We'll reuse them in the next commit.
In 67b8ef4 we changed the "edit" command to insert a "break" after the selected commit, rather than setting the selected todo to "edit". The reason for doing this was that it now works for merge commits too. Back then, I claimed "In most cases the behavior is exactly the same as before." Unfortunately that's not true, there are two reasons why the previous behavior was better (both are demonstrated by tests earlier in this branch): - when editing the last commit of a branch in the middle of a stack of branches, we are now missing the update-ref todo after it, which means that amending the commit breaks the stack - it breaks auto-amending (see the added test earlier in this branch for an explanation) For these reasons, we are going back to the previous approach of setting the selected commit to "edit" whenever possible, i.e. unless it's a merge commit. The only scenario where this could still be a problem is when you have a stack of branches, and the last commit of one of the branches in the stack is a merge commit, and you try to edit that. In my experience with stacked branches this is very unlikely, in almost all cases my stacked branches are linear.
649a8b7 to
debfe1a
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.44.1` -> `v0.45.2` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary> ### [`v0.45.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.45.2) [Compare Source](jesseduffield/lazygit@v0.45.0...v0.45.2) <!-- Release notes generated using configuration in .github/release.yml at v0.45.2 --> #### What's Changed ##### Enhancements 🔥 - Add ability to configure branch color patterns using regex by [@​mtrajano](https://github.com/mtrajano) in jesseduffield/lazygit#4130 - Collapse/uncollapse all files in tree by [@​mtrajano](https://github.com/mtrajano) in jesseduffield/lazygit#4131 - Improve undo action to restore files upon undoing a commit by [@​gabriellanata](https://github.com/gabriellanata) in jesseduffield/lazygit#4167 ##### Fixes 🔧 - Bump gocui (and tcell) by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4166 ##### Maintenance ⚙️ - Cut a new release automatically each month by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4146 - Bump tcell to fix broken deployment by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4178 #### New Contributors - [@​mtrajano](https://github.com/mtrajano) made their first contribution in jesseduffield/lazygit#4130 - [@​gabriellanata](https://github.com/gabriellanata) made their first contribution in jesseduffield/lazygit#4167 **Full Changelog**: jesseduffield/lazygit@v0.45.0...v0.45.2 ### [`v0.45.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.45.0) [Compare Source](jesseduffield/lazygit@v0.44.1...v0.45.0) <!-- Release notes generated using configuration in .github/release.yml at v0.45.0 --> Lots of great improvements in this one! Thanks to all the contributors who helped make this release happen. Apologies for the long waits between releases. As of jesseduffield/lazygit#4146 we're now (almost) guaranteed to do monthly releases. #### What's Changed ##### Enhancements 🔥 - Better branch delete confirmation by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3915 - Add a menu item to delete both local and remote branch at once by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3916 - Auto-render hyperlinks by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3914 - Allow pasting commits multiple times by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3983 - Add config option to disable switching tabs with panel jump keys (and disable by default) by [@​hgreenstein](https://github.com/hgreenstein) in jesseduffield/lazygit#3927 - We jumped the gun on this change in the last release: having the number key both select a panel and switch tabs was bad for muscle memory so it's that behaviour is now disabled by default. - Add new filter to only show tracked files in Files panel by [@​veremenko-y](https://github.com/veremenko-y) in jesseduffield/lazygit#4024 - Allow DiffContextSize to be decreased to zero by [@​LuxxxLucy](https://github.com/LuxxxLucy) in jesseduffield/lazygit#4050 - Allow user to select remote and branch when creating a MR by [@​moha-gh](https://github.com/moha-gh) in jesseduffield/lazygit#1889 - Delete range selection of branches by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4073 - Show the number of lines changed per file in working file tree view by [@​johannaschwarz](https://github.com/johannaschwarz) in jesseduffield/lazygit#4015 - Drop merge commits by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4094 - Wrap lines in staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4098 - Allow to switch branches in Commit View ([#​4115](jesseduffield/lazygit#4115)) by [@​seflue](https://github.com/seflue) in jesseduffield/lazygit#4117 - Allow on prem Azure DevOps Server pull request by [@​waynebowie99](https://github.com/waynebowie99) in jesseduffield/lazygit#3954 - Add screen-mode command line argument by [@​alewis001](https://github.com/alewis001) in jesseduffield/lazygit#4103 - Default to half-screen mode when opening with certain CLI args by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4141 - Show the alt-enter keybinding at bottom of commit description view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4136 - Add number of commits to cherry-pick confirmation prompt by [@​brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4158 ##### Fixes 🔧 - Fix copying commit author to clipboard by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3936 - Fix merge conflict resolution when file doesn't end with a LF by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3976 - Fix file icons by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3975 - Fix non-sticky range select after clicking in staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3998 - Fix scroll position when entering staging view by clicking in the main view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#3992 - Fix mouse wheel scrolling of custom patch view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4089 - Improve editing a commit by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4090 - Use custom context size in range diff by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4082 - commits panel: add missing default sort order by [@​phanirithvij](https://github.com/phanirithvij) in jesseduffield/lazygit#4097 - Fix issues with opening links and files using WSL by [@​bottino](https://github.com/bottino) in jesseduffield/lazygit#3850 - Fix moving a commit across a branch boundary in a stack of branches by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4096 - Don't preserve commit message when it's unchanged from initial message by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4110 - Fix hang when returning from shell command by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4126 - Prevent killing of unrelated processes on windows by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4137 - Add worktree option to fast forwarding operation by [@​john-mutuma](https://github.com/john-mutuma) in jesseduffield/lazygit#4051 - Don't show keybindings option in bottom line when panel is open by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4143 - Fix reset/rebase to upstream by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4151 - Avoid blank line at end of view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4152 - Adjust line number for working copy when editing a line by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4119 - Fix `micro` editor preset by [@​kytta](https://github.com/kytta) in jesseduffield/lazygit#4156 - Use interactive shell for running shell commands only if shell is bash or zsh by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4159 ##### Maintenance ⚙️ - Add performance improvements section to release notes by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#3922 - ci: update `upload-artifact` and `download-artifact` actions to v4 by [@​Juneezee](https://github.com/Juneezee) in jesseduffield/lazygit#4063 - Let schema/config.json end with a line feed by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4092 - Saner view geometry by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4085 - Cleanup background fetch by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4084 - remove duplicate secondary MouseWheelUp keybind by [@​samueldominguez](https://github.com/samueldominguez) in jesseduffield/lazygit#4120 - enhancement: Use HEX colors on file icons instead of C256 colors by [@​hasecilu](https://github.com/hasecilu) in jesseduffield/lazygit#4029 - chore: use errors.New to replace fmt.Errorf with no parameters by [@​RiceChuan](https://github.com/RiceChuan) in jesseduffield/lazygit#4107 - Fix typos by [@​NathanBaulch](https://github.com/NathanBaulch) in jesseduffield/lazygit#3920 - Bump crypto and net packages by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4144 - Tweak file icons by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4145 - Standardise on 'screen mode' naming convention by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4142 ##### Docs 📖 - Fix installation for Ubuntu in README.md by [@​shaobosong](https://github.com/shaobosong) in jesseduffield/lazygit#4031 - Fixes to lazygit Ubuntu install instructions in README.md by [@​wrecklass](https://github.com/wrecklass) in jesseduffield/lazygit#3970 - Fix typos by [@​skoch13](https://github.com/skoch13) in jesseduffield/lazygit#4121 - Add vision and design principles doc by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4053 - docs: Stylize and correct the NixOS section in README.md by [@​wadsaek](https://github.com/wadsaek) in jesseduffield/lazygit#4135 - Update chinese translation for pull requests by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4140 - Set repology table to 3 columns by [@​hasecilu](https://github.com/hasecilu) in jesseduffield/lazygit#4138 - Update instructions for using OSC52 with tmux by [@​EliasA5](https://github.com/EliasA5) in jesseduffield/lazygit#3597 - Update docs to describe use of custom commands without keybindings by [@​a-jentleman](https://github.com/a-jentleman) in jesseduffield/lazygit#3846 - documentation - describe os.openLink by [@​smangels](https://github.com/smangels) in jesseduffield/lazygit#3094 - Clarify commit message prefix mechanics by [@​zeromask1337](https://github.com/zeromask1337) in jesseduffield/lazygit#4114 #### New Contributors - [@​shaobosong](https://github.com/shaobosong) made their first contribution in jesseduffield/lazygit#4031 - [@​hgreenstein](https://github.com/hgreenstein) made their first contribution in jesseduffield/lazygit#3927 - [@​wrecklass](https://github.com/wrecklass) made their first contribution in jesseduffield/lazygit#3970 - [@​veremenko-y](https://github.com/veremenko-y) made their first contribution in jesseduffield/lazygit#4024 - [@​LuxxxLucy](https://github.com/LuxxxLucy) made their first contribution in jesseduffield/lazygit#4050 - [@​phanirithvij](https://github.com/phanirithvij) made their first contribution in jesseduffield/lazygit#4097 - [@​bottino](https://github.com/bottino) made their first contribution in jesseduffield/lazygit#3850 - [@​johannaschwarz](https://github.com/johannaschwarz) made their first contribution in jesseduffield/lazygit#4015 - [@​samueldominguez](https://github.com/samueldominguez) made their first contribution in jesseduffield/lazygit#4120 - [@​skoch13](https://github.com/skoch13) made their first contribution in jesseduffield/lazygit#4121 - [@​wadsaek](https://github.com/wadsaek) made their first contribution in jesseduffield/lazygit#4135 - [@​seflue](https://github.com/seflue) made their first contribution in jesseduffield/lazygit#4117 - [@​waynebowie99](https://github.com/waynebowie99) made their first contribution in jesseduffield/lazygit#3954 - [@​EliasA5](https://github.com/EliasA5) made their first contribution in jesseduffield/lazygit#3597 - [@​alewis001](https://github.com/alewis001) made their first contribution in jesseduffield/lazygit#4103 - [@​a-jentleman](https://github.com/a-jentleman) made their first contribution in jesseduffield/lazygit#3846 - [@​john-mutuma](https://github.com/john-mutuma) made their first contribution in jesseduffield/lazygit#4051 - [@​RiceChuan](https://github.com/RiceChuan) made their first contribution in jesseduffield/lazygit#4107 - [@​NathanBaulch](https://github.com/NathanBaulch) made their first contribution in jesseduffield/lazygit#3920 **Full Changelog**: jesseduffield/lazygit@v0.44.1...v0.45.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMzcuMSIsInVwZGF0ZWRJblZlciI6IjM5LjEzNy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
In 67b8ef4 we changed the "edit" command to insert a "break" after the
selected commit, rather than setting the selected todo to "edit". The reason for
doing this was that it now works for merge commits too.
Back then, I claimed "In most cases the behavior is exactly the same as before."
Unfortunately that's not true, there are two reasons why the previous behavior
was better (both are demonstrated by tests earlier in this branch):
we are now missing the update-ref todo after it, which means that amending the
commit breaks the stack
very convenient once you know it: whenever you stop at a commit marked with
editin an interactive rebase, you can make changes and stage them, and whenyou continue the rebase they automatically get amended to the commit you had
stopped at. This is so convenient because making changes to a commit is one of
the main reasons why you edit a commit.
For these reasons, we are going back to the previous approach of setting the
selected commit to "edit" whenever possible, i.e. unless it's a merge commit.
The only scenario where this could still be a problem is when you have a stack
of branches, and the last commit of one of the branches in the stack is a merge
commit, and you try to edit that. In my experience with stacked branches this is
very unlikely, in almost all cases my stacked branches are linear.
go generate ./...)