@@ -50,14 +50,16 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
5050
5151 deletedLineHunks , addedLineHunks := parseDiff (diff )
5252
53+ commits := self .c .Model ().Commits
54+
5355 var hashes []string
5456 warnAboutAddedLines := false
5557
5658 if len (deletedLineHunks ) > 0 {
5759 hashes , err = self .blameDeletedLines (deletedLineHunks )
5860 warnAboutAddedLines = len (addedLineHunks ) > 0
5961 } else if len (addedLineHunks ) > 0 {
60- hashes , err = self .blameAddedLines (addedLineHunks )
62+ hashes , err = self .blameAddedLines (commits , addedLineHunks )
6163 } else {
6264 return errors .New (self .c .Tr .NoChangedFiles )
6365 }
@@ -81,9 +83,8 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
8183 return fmt .Errorf ("%s\n \n %s" , message , subjects )
8284 }
8385
84- commit , index , ok := self .findCommit (hashes [0 ])
86+ commit , index , ok := self .findCommit (commits , hashes [0 ])
8587 if ! ok {
86- commits := self .c .Model ().Commits
8788 if commits [len (commits )- 1 ].Status == models .StatusMerged {
8889 // If the commit is not found, it's most likely because it's already
8990 // merged, and more than 300 commits away. Check if the last known
@@ -225,7 +226,7 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
225226 return result .ToSlice (), errg .Wait ()
226227}
227228
228- func (self * FixupHelper ) blameAddedLines (addedLineHunks []* hunk ) ([]string , error ) {
229+ func (self * FixupHelper ) blameAddedLines (commits [] * models. Commit , addedLineHunks []* hunk ) ([]string , error ) {
229230 errg := errgroup.Group {}
230231 hashesChan := make (chan []string )
231232
@@ -288,8 +289,8 @@ func (self *FixupHelper) blameAddedLines(addedLineHunks []*hunk) ([]string, erro
288289 if hashes [0 ] == hashes [1 ] {
289290 result .Add (hashes [0 ])
290291 } else {
291- _ , index1 , ok1 := self .findCommit (hashes [0 ])
292- _ , index2 , ok2 := self .findCommit (hashes [1 ])
292+ _ , index1 , ok1 := self .findCommit (commits , hashes [0 ])
293+ _ , index2 , ok2 := self .findCommit (commits , hashes [1 ])
293294 if ok1 && ok2 {
294295 result .Add (lo .Ternary (index1 < index2 , hashes [0 ], hashes [1 ]))
295296 } else if ok1 {
@@ -306,8 +307,8 @@ func (self *FixupHelper) blameAddedLines(addedLineHunks []*hunk) ([]string, erro
306307 return result .ToSlice (), errg .Wait ()
307308}
308309
309- func (self * FixupHelper ) findCommit (hash string ) (* models.Commit , int , bool ) {
310- return lo .FindIndexOf (self . c . Model (). Commits , func (commit * models.Commit ) bool {
310+ func (self * FixupHelper ) findCommit (commits [] * models. Commit , hash string ) (* models.Commit , int , bool ) {
311+ return lo .FindIndexOf (commits , func (commit * models.Commit ) bool {
311312 return commit .Hash == hash
312313 })
313314}
0 commit comments