@@ -34,14 +34,14 @@ func NewRebaseCommands(
3434 }
3535}
3636
37- func (self * RebaseCommands ) RewordCommit (commits []* models.Commit , index int , summary string , description string ) error {
37+ func (self * RebaseCommands ) RewordCommit (commits []* models.Commit , index int , parentIdx int , summary string , description string ) error {
3838 // This check is currently unreachable (handled in LocalCommitsController.reword),
3939 // but kept as a safeguard in case this method is used elsewhere.
4040 if self .config .NeedsGpgSubprocessForCommit () {
4141 return errors .New (self .Tr .DisabledForGPG )
4242 }
4343
44- err := self .BeginInteractiveRebaseForCommit (commits , index , false )
44+ err := self .BeginInteractiveRebaseForCommit (commits , index , parentIdx , false )
4545 if err != nil {
4646 return err
4747 }
@@ -55,44 +55,44 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su
5555 return self .ContinueRebase ()
5656}
5757
58- func (self * RebaseCommands ) RewordCommitInEditor (commits []* models.Commit , index int ) (* oscommands.CmdObj , error ) {
58+ func (self * RebaseCommands ) RewordCommitInEditor (commits []* models.Commit , index int , parentIdx int ) (* oscommands.CmdObj , error ) {
5959 changes := []daemon.ChangeTodoAction {{
6060 Hash : commits [index ].Hash (),
6161 NewAction : todo .Reword ,
6262 }}
6363 self .os .LogCommand (logTodoChanges (changes ), false )
6464
6565 return self .PrepareInteractiveRebaseCommand (PrepareInteractiveRebaseCommandOpts {
66- baseHashOrRoot : getBaseHashOrRoot (commits , index + 1 ),
66+ baseHashOrRoot : getBaseHashOrRoot (commits , parentIdx ),
6767 instruction : daemon .NewChangeTodoActionsInstruction (changes ),
6868 }), nil
6969}
7070
71- func (self * RebaseCommands ) ResetCommitAuthor (commits []* models.Commit , start , end int ) error {
72- return self .GenericAmend (commits , start , end , func (_ * models.Commit ) error {
71+ func (self * RebaseCommands ) ResetCommitAuthor (commits []* models.Commit , start , end int , parentIdx int ) error {
72+ return self .GenericAmend (commits , start , end , parentIdx , func (_ * models.Commit ) error {
7373 return self .commit .ResetAuthor ()
7474 })
7575}
7676
77- func (self * RebaseCommands ) SetCommitAuthor (commits []* models.Commit , start , end int , value string ) error {
78- return self .GenericAmend (commits , start , end , func (_ * models.Commit ) error {
77+ func (self * RebaseCommands ) SetCommitAuthor (commits []* models.Commit , start , end int , parentIdx int , value string ) error {
78+ return self .GenericAmend (commits , start , end , parentIdx , func (_ * models.Commit ) error {
7979 return self .commit .SetAuthor (value )
8080 })
8181}
8282
83- func (self * RebaseCommands ) AddCommitCoAuthor (commits []* models.Commit , start , end int , value string ) error {
84- return self .GenericAmend (commits , start , end , func (commit * models.Commit ) error {
83+ func (self * RebaseCommands ) AddCommitCoAuthor (commits []* models.Commit , start , end int , parentIdx int , value string ) error {
84+ return self .GenericAmend (commits , start , end , parentIdx , func (commit * models.Commit ) error {
8585 return self .commit .AddCoAuthor (commit .Hash (), value )
8686 })
8787}
8888
89- func (self * RebaseCommands ) GenericAmend (commits []* models.Commit , start , end int , f func (commit * models.Commit ) error ) error {
89+ func (self * RebaseCommands ) GenericAmend (commits []* models.Commit , start , end int , parentIdx int , f func (commit * models.Commit ) error ) error {
9090 if start == end && models .IsHeadCommit (commits , start ) {
9191 // we've selected the top commit so no rebase is required
9292 return f (commits [start ])
9393 }
9494
95- err := self .BeginInteractiveRebaseForCommitRange (commits , start , end , false )
95+ err := self .BeginInteractiveRebaseForCommitRange (commits , start , end , parentIdx , false )
9696 if err != nil {
9797 return err
9898 }
@@ -139,13 +139,8 @@ func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int
139139 }).Run ()
140140}
141141
142- func (self * RebaseCommands ) InteractiveRebase (commits []* models.Commit , startIdx int , endIdx int , action todo.TodoCommand ) error {
143- baseIndex := endIdx + 1
144- if action == todo .Squash || action == todo .Fixup {
145- baseIndex ++
146- }
147-
148- baseHashOrRoot := getBaseHashOrRoot (commits , baseIndex )
142+ func (self * RebaseCommands ) InteractiveRebase (commits []* models.Commit , startIdx int , endIdx int , parentIdx int , action todo.TodoCommand ) error {
143+ baseHashOrRoot := getBaseHashOrRoot (commits , parentIdx )
149144
150145 changes := lo .FilterMap (commits [startIdx :endIdx + 1 ], func (commit * models.Commit , _ int ) (daemon.ChangeTodoAction , bool ) {
151146 return daemon.ChangeTodoAction {
@@ -294,7 +289,7 @@ func (self *RebaseCommands) getHashOfLastCommitMade() (string, error) {
294289}
295290
296291// AmendTo amends the given commit with whatever files are staged
297- func (self * RebaseCommands ) AmendTo (commits []* models.Commit , commitIndex int ) error {
292+ func (self * RebaseCommands ) AmendTo (commits []* models.Commit , commitIndex int , parentIdx int ) error {
298293 commit := commits [commitIndex ]
299294
300295 if err := self .commit .CreateFixupCommit (commit .Hash ()); err != nil {
@@ -307,7 +302,7 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e
307302 }
308303
309304 return self .PrepareInteractiveRebaseCommand (PrepareInteractiveRebaseCommandOpts {
310- baseHashOrRoot : getBaseHashOrRoot (commits , commitIndex + 1 ),
305+ baseHashOrRoot : getBaseHashOrRoot (commits , parentIdx ),
311306 overrideEditor : true ,
312307 instruction : daemon .NewMoveFixupCommitDownInstruction (commit .Hash (), fixupHash , true ),
313308 }).Run ()
@@ -401,7 +396,7 @@ func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) er
401396// BeginInteractiveRebaseForCommit starts an interactive rebase to edit the current
402397// commit and pick all others. After this you'll want to call `self.ContinueRebase()
403398func (self * RebaseCommands ) BeginInteractiveRebaseForCommit (
404- commits []* models.Commit , commitIndex int , keepCommitsThatBecomeEmpty bool ,
399+ commits []* models.Commit , commitIndex int , parentIdx int , keepCommitsThatBecomeEmpty bool ,
405400) error {
406401 if commitIndex < len (commits ) && commits [commitIndex ].IsMerge () {
407402 if self .config .NeedsGpgSubprocessForCommit () {
@@ -415,11 +410,11 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
415410 }).Run ()
416411 }
417412
418- return self .BeginInteractiveRebaseForCommitRange (commits , commitIndex , commitIndex , keepCommitsThatBecomeEmpty )
413+ return self .BeginInteractiveRebaseForCommitRange (commits , commitIndex , commitIndex , parentIdx , keepCommitsThatBecomeEmpty )
419414}
420415
421416func (self * RebaseCommands ) BeginInteractiveRebaseForCommitRange (
422- commits []* models.Commit , start , end int , keepCommitsThatBecomeEmpty bool ,
417+ commits []* models.Commit , start , end int , parentIdx int , keepCommitsThatBecomeEmpty bool ,
423418) error {
424419 if len (commits )- 1 < end {
425420 return errors .New ("index outside of range of commits" )
@@ -442,7 +437,7 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommitRange(
442437 self .os .LogCommand (logTodoChanges (changes ), false )
443438
444439 return self .PrepareInteractiveRebaseCommand (PrepareInteractiveRebaseCommandOpts {
445- baseHashOrRoot : getBaseHashOrRoot (commits , end + 1 ),
440+ baseHashOrRoot : getBaseHashOrRoot (commits , parentIdx ),
446441 overrideEditor : true ,
447442 keepCommitsThatBecomeEmpty : keepCommitsThatBecomeEmpty ,
448443 instruction : daemon .NewChangeTodoActionsInstruction (changes ),
@@ -515,8 +510,8 @@ func (self *RebaseCommands) runSkipEditorCommand(cmdObj *oscommands.CmdObj) erro
515510}
516511
517512// DiscardOldFileChanges discards changes to a file from an old commit
518- func (self * RebaseCommands ) DiscardOldFileChanges (commits []* models.Commit , commitIndex int , filePaths []string ) error {
519- if err := self .BeginInteractiveRebaseForCommit (commits , commitIndex , false ); err != nil {
513+ func (self * RebaseCommands ) DiscardOldFileChanges (commits []* models.Commit , commitIndex int , parentIdx int , filePaths []string ) error {
514+ if err := self .BeginInteractiveRebaseForCommit (commits , commitIndex , parentIdx , false ); err != nil {
520515 return err
521516 }
522517
0 commit comments