Skip to content

Commit

Permalink
fixup! Create fixup commit at end of its branch when there's a stack …
Browse files Browse the repository at this point in the history
…of branches
  • Loading branch information
stefanhaller committed Sep 7, 2024
1 parent 59bc352 commit 54913f7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
return err
}

if err := self.moveFixupCommitToCurrentBranchOfStack(commit); err != nil {
if err := self.moveFixupCommitToOwnerStackedBranch(commit); err != nil {
return err
}

Expand Down Expand Up @@ -928,7 +928,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
})
}

func (self *LocalCommitsController) moveFixupCommitToCurrentBranchOfStack(targetCommit *models.Commit) error {
func (self *LocalCommitsController) moveFixupCommitToOwnerStackedBranch(targetCommit *models.Commit) error {
if self.c.Git().Version.IsOlderThan(2, 38, 0) {
// Git 2.38.0 introduced the `rebase.updateRefs` config option. Don't
// move the commit down with older versions, as it would break the stack.
Expand All @@ -955,21 +955,21 @@ func (self *LocalCommitsController) moveFixupCommitToCurrentBranchOfStack(target
return nil
}

headOfCurrentBranchIdx := -1
headOfOwnerBranchIdx := -1
for i := self.context().GetSelectedLineIdx(); i > 0; i-- {
if lo.SomeBy(self.c.Model().Branches, func(b *models.Branch) bool {
return b.CommitHash == self.c.Model().Commits[i].Hash
}) {
headOfCurrentBranchIdx = i
headOfOwnerBranchIdx = i
break
}
}

if headOfCurrentBranchIdx == -1 {
if headOfOwnerBranchIdx == -1 {
return nil
}

return self.c.Git().Rebase.MoveFixupCommitDown(self.c.Model().Commits, headOfCurrentBranchIdx)
return self.c.Git().Rebase.MoveFixupCommitDown(self.c.Model().Commits, headOfOwnerBranchIdx)
}

func (self *LocalCommitsController) createAmendCommit(commit *models.Commit, includeFileChanges bool) error {
Expand All @@ -995,7 +995,7 @@ func (self *LocalCommitsController) createAmendCommit(commit *models.Commit, inc
return err
}

if err := self.moveFixupCommitToCurrentBranchOfStack(commit); err != nil {
if err := self.moveFixupCommitToOwnerStackedBranch(commit); err != nil {
return err
}

Expand Down

0 comments on commit 54913f7

Please sign in to comment.