Skip to content

Commit 67b8ef4

Browse files
committed
Edit by breaking after current commit
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).
1 parent bb856ad commit 67b8ef4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/commands/git_commands/rebase.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in
117117
return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run()
118118
}
119119

120+
func (self *RebaseCommands) InteractiveRebaseBreakAfter(commits []*models.Commit, index int) error {
121+
todo, sha, err := self.BuildSingleActionTodo(commits, index-1, "pick")
122+
if err != nil {
123+
return err
124+
}
125+
126+
todo = append(todo, TodoLine{Action: "break", Commit: nil})
127+
return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run()
128+
}
129+
120130
// PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase
121131
// we tell git to run lazygit to edit the todo list, and we pass the client
122132
// lazygit a todo string to write to the todo file
@@ -400,5 +410,9 @@ type TodoLine struct {
400410
}
401411

402412
func (self *TodoLine) ToString() string {
403-
return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n"
413+
if self.Action == "break" {
414+
return self.Action + "\n"
415+
} else {
416+
return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n"
417+
}
404418
}

pkg/gui/controllers/local_commits_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ func (self *LocalCommitsController) edit(commit *models.Commit) error {
298298

299299
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
300300
self.c.LogAction(self.c.Tr.Actions.EditCommit)
301-
return self.interactiveRebase("edit")
301+
err := self.git.Rebase.InteractiveRebaseBreakAfter(self.model.Commits, self.context().GetSelectedLineIdx())
302+
return self.helpers.MergeAndRebase.CheckMergeOrRebase(err)
302303
})
303304
}
304305

0 commit comments

Comments
 (0)