Skip to content

Commit d675eb6

Browse files
committed
Don't allow changing the type of certain rebase todos
We already show "merge" todo entries when starting an interactive rebase with --rebase-merges outside of lazygit. Changing the type of a merge entry to "pick" or "edit" doesn't make sense and shouldn't be allowed. Earlier in this branch we have started to show "update-ref" entries, these can't be changed either (they can be moved, though). You might argue that it should be possible to change them to "drop", but in the case of "update-ref" this doesn't make sense either, because "drop" needs a Sha and we don't have one here. Also, you would then be able to later change it back to "pick", so we would have to remember that this isn't allowed for this particular drop entry; that's messy, so just disallow all editing.
1 parent dc4e88f commit d675eb6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/gui/controllers/local_commits_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/jesseduffield/lazygit/pkg/gui/context"
1010
"github.com/jesseduffield/lazygit/pkg/gui/types"
1111
"github.com/jesseduffield/lazygit/pkg/utils"
12+
"github.com/samber/lo"
1213
)
1314

1415
type (
@@ -348,6 +349,10 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoComma
348349
return true, self.c.ErrorMsg(self.c.Tr.LcRewordNotSupported)
349350
}
350351

352+
if allowed := isChangeOfRebaseTodoAllowed(action); !allowed {
353+
return true, self.c.ErrorMsg(self.c.Tr.LcChangingThisActionIsNotAllowed)
354+
}
355+
351356
self.c.LogAction("Update rebase TODO")
352357
self.c.LogCommand(
353358
fmt.Sprintf("Updating rebase action of commit %s to '%s'", commit.ShortSha(), action.String()),
@@ -759,3 +764,16 @@ func (self *LocalCommitsController) paste() error {
759764
func (self *LocalCommitsController) isHeadCommit() bool {
760765
return models.IsHeadCommit(self.model.Commits, self.context().GetSelectedLineIdx())
761766
}
767+
768+
func isChangeOfRebaseTodoAllowed(action todo.TodoCommand) bool {
769+
allowedActions := []todo.TodoCommand{
770+
todo.Pick,
771+
todo.Drop,
772+
todo.Edit,
773+
todo.Fixup,
774+
todo.Squash,
775+
todo.Reword,
776+
}
777+
778+
return lo.Contains(allowedActions, action)
779+
}

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ type TranslationSet struct {
219219
YouAreHere string
220220
YouDied string
221221
LcRewordNotSupported string
222+
LcChangingThisActionIsNotAllowed string
222223
LcCherryPickCopy string
223224
LcCherryPickCopyRange string
224225
LcPasteCommits string
@@ -887,6 +888,7 @@ func EnglishTranslationSet() TranslationSet {
887888
YouAreHere: "YOU ARE HERE",
888889
YouDied: "YOU DIED!",
889890
LcRewordNotSupported: "rewording commits while interactively rebasing is not currently supported",
891+
LcChangingThisActionIsNotAllowed: "changing this kind of rebase todo entry is not allowed",
890892
LcCherryPickCopy: "copy commit (cherry-pick)",
891893
LcCherryPickCopyRange: "copy commit range (cherry-pick)",
892894
LcPasteCommits: "paste commits (cherry-pick)",

0 commit comments

Comments
 (0)