Skip to content

Conversation

@stefanhaller
Copy link
Collaborator

  • PR Description

Instead of rebasing from the commit below the current one and then setting the
current one to "edit", we rebase from the current one and insert a "break" after
it. In most cases the behavior is exactly the same as before, except that the
new method also works if the current commit is a merge commit. This is useful if
you want to create a new commit at the very beginning of your branch (before the
first commit of your branch), if the last commit before that is a merge.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go run scripts/cheatsheet/main.go generate)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
    • I didn't add or adapt any tests, because for the normal cases the behavior should be unchanged
  • Text is internationalised (see here)
  • Docs (specifically docs/Config.md) have been updated if necessary
  • You've read through your own file changes for silly mistakes etc
We need this because the next commit is going to make use of the "break" interactive rebase instruction, which was added in 2.20.
Instead of rebasing from the commit below the current one and then setting the current one to "edit", we rebase from the current one and insert a "break" after it. In most cases the behavior is exactly the same as before, except that the new method also works if the current commit is a merge commit. This is useful if you want to create a new commit at the very beginning of your branch (by editing the last commit before your branch).
}

if version.IsOlderThan(2, 0, 0) {
if version.IsOlderThan(2, 20, 0) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jesseduffield Not sure you'll agree with this. Personally I find it a bit insane to support nine-year-old git versions, so I'd have no problem with this change; but if you object, I think it should be possible to fall back to the old way of editing a commit if the git version is older than 2.20. Let me know what you prefer.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm fine with it. 2.0 was arbitrary in the first place

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, great. I added a commit to revert a compatibility fix that was added for supporting versions older than 2.7, which we now no longer need; @Ryooooooga, please have a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2023

Uffizzi Preview Environment deployment-16604

☁️ https://app.uffizzi.com/github.com/jesseduffield/lazygit/pull/2451

📄 View Application Logs etc.

What is Uffizzi? Learn more

@jesseduffield
Copy link
Owner

This is great, I'm all for it. We currently raise an error upon trying to start an interactive rebase from the first commit i.e.:

// pkg/commands/git_commands/rebase.go:165 if len(commits) <= baseIndex { return nil, "", errors.New(self.Tr.CannotRebaseOntoFirstCommit)	}

Is this check no longer required thanks to this PR? If so, would be good to remove that guard and add an integration test showing that this works from the first commit

@stefanhaller
Copy link
Collaborator Author

Is this check no longer required thanks to this PR? If so, would be good to remove that guard and add an integration test showing that this works from the first commit

Removing the guard is not possible, we still need it to guard against rewording the first commit, which is still not possible. (Side note: when rewording, you get the error message only after having typed the new commit message, it would be nice if we would error out before that.)

But I added an integration test for editing the first commit, which is now indeed possible.

Since we now require git 2.20, we don't need this any more. This reverts commit 7c5f339.
@stefanhaller stefanhaller force-pushed the edit-by-breaking-after-current-commit branch from 87020e5 to ac9515d Compare February 19, 2023 15:13
@stefanhaller
Copy link
Collaborator Author

But I added an integration test for editing the first commit, which is now indeed possible.

I take that back, this test doesn't belong here. The fact that this branch also allows editing the first commit is a bit of a coincidence. I dropped the test again from here.

I created another PR which is independent from this one, which allows all interactive rebase operations down to the initial commit; I added the test there (and a few others): #2453

@jesseduffield jesseduffield merged commit 15962e4 into jesseduffield:master Feb 20, 2023
@jesseduffield
Copy link
Owner

Tested it locally, all works fine. Thanks for making this!

@stefanhaller stefanhaller deleted the edit-by-breaking-after-current-commit branch February 20, 2023 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants