Skip to content

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

This is often useful to extract preparatory refactoring commits from a bigger one. It works best when selecting only entire hunks or even entire files; if partial hunks are in the patch, you are likely to get conflicts.

Along the way, fix rewording merge commits. (Not because I find this super important, but just because I came across the code while working on this.)

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

I almost broke this during the development of this branch, so add a test to
guard against that. The point here is that the stack remains intact, i.e. the
renamed commit is the head of the lower branch, and thus shows the "*".
…t of a stacked branch

I almost broke this during the development of this branch, so add a test to
guard against that. The point here is that the stack remains intact, i.e. the
newly created commit is the last commit of the lower branch, and thus shows the
"*".
This currently fails with an error.
…h merge commit

BeginInteractiveRebaseForCommit is used for all the patch commands, and for
rewording. It works by setting the commit we want to stop at to 'edit'; this
doesn't work for merge commits. This wasn't a problem for the patch commands so
far, because you typically don't use custom patches with merge commits (although
we don't prevent this; maybe we should?).

However, it was a problem when you tried to reword a merge commit; this
previously failed with an error, as the test added in the previous commit
demonstrated.

Also, we want to add a new patch command that has to stop *before* the selected
commit (pull patch to new commit before the original one), and this wouldn't
work for the first commit in a feature branch, because it would have to set the
last commit before that to 'edit', which isn't possible if that's a merge (which
is likely).

To fix all this, use a 'break' before the selected commit if the commit is a
merge. It is important that we only do it in that case and not always, otherwise
we would break the new regression tests that were added a few commits ago.
@stefanhaller stefanhaller added the enhancement New feature or request label May 10, 2025
…nal commit"

This is often useful to extract preparatory refactoring commits from a bigger
one.
@stefanhaller stefanhaller force-pushed the move-patch-to-new-commit-before-original-commit branch from b4043cb to f6d1333 Compare May 10, 2025 16:57
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for ef1da6f1 96.08%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (ef1da6f) Report Missing Report Missing Report Missing
Head commit (f6d1333) 56326 48924 86.86%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4552) 332 319 96.08%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

LGTM, nice one

@stefanhaller stefanhaller merged commit a27db87 into master May 11, 2025
14 checks passed
@stefanhaller stefanhaller deleted the move-patch-to-new-commit-before-original-commit branch May 11, 2025 11:55
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 23, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.50.0` -> `v0.51.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.51.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.51.0)

[Compare Source](jesseduffield/lazygit@v0.50.0...v0.51.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.51.0 -->

#### What's Changed

##### Enhancements 🔥

-   Clean up the configuration of where a custom command's output goes by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4525
-   Add custom patch command "Move patch into new commit before the original commit" by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4552
-   Make '>' first jump to the beginning of the branch, and only then to the first commit by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4544
-   Add an alternate keybinding (default <c-s>) for ConfirmInEditor by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4532
-   Print migration changes to the console when migrating config file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4548

##### Fixes 🔧

-   Migrate deprecated AllBranchesLogCmd to AllBranchesLogCmds by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4345
-   Clear preserved commit message when entering CommitEditorPanel by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4558
-   Split behavior of rendering allBranchesLogCmd and switching to next cmd by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4574
-   Fix possible crash with auto-forwarding branches by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4565
-   Fix main view occasionally scrolling to the top on its own when focused by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4573
-   Fix home and end keys in prompts by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4554
-   Fix crash when clicking in the status view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4567

##### Maintenance ⚙️

-   Clean up utils package by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4538

##### Docs 📖

-   reword documentation for git.autoForwardBranches by [@&#8203;sean-xyz](https://github.com/sean-xyz) in jesseduffield/lazygit#4545

#### New Contributors

-   [@&#8203;sean-xyz](https://github.com/sean-xyz) made their first contribution in jesseduffield/lazygit#4545

**Full Changelog**: jesseduffield/lazygit@v0.50.0...v0.51.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:eyJjcmVhdGVkSW5WZXIiOiI0MC4yMi4wIiwidXBkYXRlZEluVmVyIjoiNDAuMjMuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants