Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Continue/abort a conflicted cherry-pick or revert #4441

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

This is part one of a four part series of PRs that improve the cherry-pick and revert experience.

With this first PR we make it possible to continue or abort a cherry-pick or revert operation, in the same way you can continue or abort a rebase or merge. Currently this is only relevant for revert, because lazygit doesn't use git cherry-pick for copying/pasting commits. This will change in a later PR in this series though, so here we are already preparing for that.

Fixes #1807

  • 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

@stefanhaller stefanhaller added the enhancement New feature or request label Mar 31, 2025
@stefanhaller stefanhaller force-pushed the continue-and-abort-for-revert-and-cherrypick branch 3 times, most recently from 253b2f7 to 82ebc80 Compare March 31, 2025 17:39
Copy link

codacy-production bot commented Mar 31, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 61636d81 97.89%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (61636d8) Report Missing Report Missing Report Missing
Head commit (2d897e1) 54522 47309 86.77%

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 (#4441) 284 278 97.89%

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.

@stefanhaller stefanhaller force-pushed the continue-and-abort-for-revert-and-cherrypick branch from 82ebc80 to 0badb30 Compare April 5, 2025 09:26
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.

Nice work. One thing

REBASE_MODE_REBASING
REBASE_MODE_MERGING
// this means we're neither rebasing nor merging, cherry-picking, or reverting
WORKING_TREE_STATE_NONE WorkingTreeState = 0
Copy link
Owner

@jesseduffield jesseduffield Apr 6, 2025

Choose a reason for hiding this comment

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

I don't like how we're using the same type (WorkingTreeState) for the bits as for the bitfield. Naively I would expect that I could directly check if workingTreeState == WORKING_TREE_STATE_CHERRY_PICKING but that's really only going to return true if we're only cherry picking and not also merging. I also can't do if workingTreeState == WORKING_TREE_STATE_CHERRY_PICKING || workingTreeState == WORKING_TREE_STATE_REBASING to ask if it's either cherry picking or rebasing.

So I'm wondering, how about we just have a struct of booleans:

type WorkingTreeState struct {
  rebasing bool
  merging bool
  cherryPicking bool
  reverting bool
}

And then define methods on that struct. We can still have the .Effective() method which returns the enum value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Yes, a struct is an improvement to this.

I couldn't do this as a fixup, so I rebased and force-pushed. I added dceb196 as a preparation, and then d2573dc is the changed commit. The rest of the branch is unchanged except for adaptions to the new API.

@stefanhaller stefanhaller force-pushed the continue-and-abort-for-revert-and-cherrypick branch from 0badb30 to 5d957ce Compare April 7, 2025 12:42
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

When debugging an integration test that involves some behind-the-scenes
rebasing, the daemon lazygit would also wait for a debugger to attach. This is
very confusing because the test seems to hang; once you figured out what's going
on, it's inconvenient because you need to attach a debugger to the daemon every
time you debug the test.

Now, it would sometimes be useful to be able to debug the daemon itself (whether
inside an integration test, or during normal usage), and I have often wished to
be able to do that. We might introduce an additional env var (and command-line
option?) to enable this; but that's out of scope here.
All test cases set it to enums.REBASE_MODE_NONE, so we can simplify things a
little bit by hard-coding that. This makes the changes in the following commits
a little easier.
We want to get rid of RebaseMode, and using the more general WorkingTreeState
will later allow us to also show cherry-pick or revert todos.
- Remove REBASE_MODE_NORMAL. It is not the "normal" mode anyway, rather a legacy
mode; we have removed support for it in eb0f7e3, so there's no point in
representing it in the enum.
- Remove distinction between REBASE_MODE_REBASING and REBASE_MODE_INTERACTIVE;
these are the same now.
- Rename StatusCommands.IsInInteractiveRebase to IsInRebase.
- Remove StatusCommands.RebaseMode; use StatusCommands.IsInRebase instead.
We're about to add more possible values (reverting and cherry-picking), so
working tree state seems like a more suitable name.
The situation is that you perform a rebase, and one of the commits becomes empty
during the rebase, in a way that couldn't be predicted before the rebase
started. To explain: git rebase has some logic where it immediately discards
commits if it can tell that they already exist in the branch being rebased onto;
it does this by looking at the patch ids of the commits to work out which
commits already exist upstream. But for those commits that become empty even
though there isn't a corresponding commit upstream, git stops with an error, and
lazygit detects this (in CheckMergeOrRebaseWithRefreshOptions) and automatically
continues the rebase.

This all works fine; I'm adding this test because I almost broke this during
development of this branch, so I'm adding it to guard against regressions.
It looks like enums.go was supposed to be file that collects a bunch of enums,
but actually there's only one in there, and since it has methods, it deserves to
be in a file of its own, named after the type.
When you are in the middle of a rebase, and you cherry-pick a commit which
conflicts, it helps to be clear on whether you are prompted to continue the
cherry-pick or the rebase.
This works already (except that the "you are here" marker is not right yet, but
that's an issue for another PR), just add a test that verifies it.
This way we get the usual menu for viewing the conflicts or aborting, like for
rebases.
@stefanhaller stefanhaller force-pushed the continue-and-abort-for-revert-and-cherrypick branch from 5d957ce to 2d897e1 Compare April 10, 2025 09:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Continuing a revert after fixing a merge conflict does not work
2 participants