1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Allow squashing fixups above the first commit of a repo

This includes amending changes into a given commit, since that's implemented in
terms of the former.
This commit is contained in:
Stefan Haller
2023-02-20 08:29:43 +01:00
parent 7351907474
commit c5cd217a65
5 changed files with 105 additions and 8 deletions

View File

@ -198,12 +198,12 @@ func (self *RebaseCommands) BuildSingleActionTodo(commits []*models.Commit, acti
}
// AmendTo amends the given commit with whatever files are staged
func (self *RebaseCommands) AmendTo(sha string) error {
if err := self.commit.CreateFixupCommit(sha); err != nil {
func (self *RebaseCommands) AmendTo(commit *models.Commit) error {
if err := self.commit.CreateFixupCommit(commit.Sha); err != nil {
return err
}
return self.SquashAllAboveFixupCommits(sha)
return self.SquashAllAboveFixupCommits(commit)
}
// EditRebaseTodo sets the action at a given index in the git-rebase-todo file
@ -258,12 +258,17 @@ func (self *RebaseCommands) MoveTodoDown(index int) error {
}
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error {
func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) error {
shaOrRoot := commit.Sha + "^"
if commit.IsFirstCommit() {
shaOrRoot = "--root"
}
return self.runSkipEditorCommand(
self.cmd.New(
fmt.Sprintf(
"git rebase --interactive --rebase-merges --autostash --autosquash %s^",
sha,
"git rebase --interactive --rebase-merges --autostash --autosquash %s",
shaOrRoot,
),
),
)