summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-04-19 08:19:17 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-04-29 07:28:33 +0200
commit3fe4db9316f2bcfb168c6585acee425831f9b04b (patch)
treeef190b8ac3e8a82194d7b46ac14f57b8880bca11 /pkg/commands
parent185bbf0c75f9ea0d645fb0df6893169f7ae07340 (diff)
Make RebaseCommands.AmendTo more robust
This fixes two problems with the "amend commit with staged changes" command: 1. Amending to a fixup commit didn't work (this would create a commmit with the title "fixup! fixup! original title" and keep that at the top of the branch) 2. Unrelated fixup commits would be squashed too. The added integration test verifies that both of these problems are fixed.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/rebase.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go
index be5384773..50c599a66 100644
--- a/pkg/commands/git_commands/rebase.go
+++ b/pkg/commands/git_commands/rebase.go
@@ -214,12 +214,24 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
}
// AmendTo amends the given commit with whatever files are staged
-func (self *RebaseCommands) AmendTo(commit *models.Commit) error {
+func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) error {
+ commit := commits[commitIndex]
+
if err := self.commit.CreateFixupCommit(commit.Sha); err != nil {
return err
}
- return self.SquashAllAboveFixupCommits(commit)
+ // Get the sha of the commit we just created
+ fixupSha, err := self.cmd.New("git rev-parse --verify HEAD").RunWithOutput()
+ if err != nil {
+ return err
+ }
+
+ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
+ baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1),
+ overrideEditor: true,
+ instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Sha, fixupSha),
+ }).Run()
}
// EditRebaseTodo sets the action for a given rebase commit in the git-rebase-todo file