-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix applying custom patches to a dirty working tree #4674
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
Fix applying custom patches to a dirty working tree #4674
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 preferencesFootnotes
|
Curiously, the function was never called so far, but we're going to use it later in this branch.
This is functionality that works already, we only add the test for more complete test coverage. However, there's a detail problem, and the test demonstrates this: we keep the stash even if there was no conflict. We'll fix this next.
The tests show that this currently fails with the confusing error message "does not match index", regardless of whether the patch conflicts with the modifications or not. We'll improve this in the next commit. I don't bother adding tests for reverting a patch, as the code is basically the same as for apply.
Unlike moving a patch to the index, applying or reverting a patch didn't auto-stash, which means that applying a patch when there's a modified (but unstaged) file in the working tree would error out with the message "error: file1: does not match index", regardless of whether those modifications conflict with the patch or not. To fix this, we *could* add auto-stashing like we do for the "move patch to index" command. However, in this case we rather simply stage the affected files (after asking for confirmation). This has a few advantages: - it only changes the staging state of those files that are contained in the patch (whereas auto-stashing always changes all files to unstaged) - it doesn't unnecessarily show a confirmation if none of the modified files are affected by the patch - if the patch conflicts with the modified files, the conflicts were "backwards" ("ours" was the patch, "theirs" the modified file); it is more logical if "ours" is the current state of the file, and "theirs" is the patch. It's a little unfortunate that the behavior isn't exactly the same as for "move patch to index", but for that one we do need the auto-stash because of the rebase that runs behind the scenes.
068daaa
to
3df894e
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.52.0` -> `v0.53.0` | 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.53.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.53.0) [Compare Source](jesseduffield/lazygit@v0.52.0...v0.53.0) <!-- Release notes generated using configuration in .github/release.yml at v0.53.0 --> This is the first lazygit release after Jesse [passed the maintainership to me](jesseduffield/lazygit#4655) ([@​stefanhaller](https://github.com/stefanhaller)), and I'm excited (and a little bit nervous 😄) about it. No big new features this time, but lots of smaller quality-of-life improvements. The one that makes the biggest difference for me is an improved hunk selection mode in the staging view (in case you didn't know, you can switch from the normal line selection mode to hunk mode by pressing `a`). This now works a bit more fine-grained, by selecting groups of added or deleted lines rather than entire hunks, which often consist of several such groups. With this change I find that I prefer hunk mode over line mode in most cases, so I added a user config to switch to hunk automatically upon entering the staging view; it is off by default, but I encourage you to enable it (`gui.useHunkModeInStagingView`) to see if you like it as much as I do. Feedback about this is welcome; please comment on [the MR](jesseduffield/lazygit#4684) if you have any. The detailed list of all changes follows: #### What's Changed ##### Enhancements 🔥 - Add option to disable warning when amending last commit by [@​johnhamlin](https://github.com/johnhamlin) in jesseduffield/lazygit#4640 - Add bold style for border by [@​aidancz](https://github.com/aidancz) in jesseduffield/lazygit#4644 - Add credential prompts for PKCS11-based SSH keys by [@​Jadeiin](https://github.com/Jadeiin) in jesseduffield/lazygit#4646 - Show annotation information for selected tag by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4663 - Show stash name for selected stash by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4673 - Auto-stash modified files when cherry-picking or reverting commits by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4683 - Move to next stageable line when adding a line to a custom patch by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4675 - Improve hunk selection mode in staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4684 - Add user config to use hunk mode by default when entering staging view by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4685 ##### Fixes 🔧 - Fix stash operations when branch named 'stash' exists by [@​ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4641 - Fix moving a custom patch from the very first commit of the history to a later commit by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4631 - Fix DEFAULT\_REMOTE\_ICON character code by [@​bedlamzd](https://github.com/bedlamzd) in jesseduffield/lazygit#4653 - Show GPG error before entering commit editor when rewording non-latest commits by [@​m04f](https://github.com/m04f) in jesseduffield/lazygit#4660 - Fix branch head icon appearing at head commit when a remote or tag exists with the same name as the current branch by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4669 - Fix applying custom patches to a dirty working tree by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4674 - Collapse selection after deleting a range of branches or stashes by [@​nileric](https://github.com/nileric) in jesseduffield/lazygit#4661 ##### Maintenance ⚙️ - Instantiate mutexes by value by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4632 - Bump github.com/cloudflare/circl from 1.6.0 to 1.6.1 by [@​dependabot](https://github.com/dependabot) in jesseduffield/lazygit#4633 - Update linter by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4671 - Some code cleanups to the "discard file changes from commit" feature by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4679 - Change Refresh to not return an error by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4680 ##### Docs 📖 - Fix formatting of a keyboard shortcut in the README.md by [@​DanOpcode](https://github.com/DanOpcode) in jesseduffield/lazygit#4678 ##### I18n 🌎 - Update translations from Crowdin by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4686 #### New Contributors - [@​johnhamlin](https://github.com/johnhamlin) made their first contribution in jesseduffield/lazygit#4640 - [@​aidancz](https://github.com/aidancz) made their first contribution in jesseduffield/lazygit#4644 - [@​bedlamzd](https://github.com/bedlamzd) made their first contribution in jesseduffield/lazygit#4653 - [@​Jadeiin](https://github.com/Jadeiin) made their first contribution in jesseduffield/lazygit#4646 - [@​m04f](https://github.com/m04f) made their first contribution in jesseduffield/lazygit#4660 - [@​DanOpcode](https://github.com/DanOpcode) made their first contribution in jesseduffield/lazygit#4678 - [@​nileric](https://github.com/nileric) made their first contribution in jesseduffield/lazygit#4661 **Full Changelog**: jesseduffield/lazygit@v0.52.0...v0.53.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:eyJjcmVhdGVkSW5WZXIiOiI0MC42Mi4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Applying or reverting a custom patch when one of the files contained in the patch had unstaged modifications in the working tree would fail with the confusing error message "does not match index", regardless of whether those modifications conflicted with the patch or not. You would expect this to just work if there are no conflicts, or to get the usual conflict markers if there are. It was possible to work around this by manually staging those files, but few people knew about this. Fix this by staging the files (after asking for confirmation).
Also, fix a minor problem where an auto-stash for the "move patch to index" command was forgotten to be dropped.