diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-22 15:56:30 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 5874529f4310c6b4b0abdfcef714ff6f6cc8afd5 (patch) | |
tree | 3a225e081659c52cd548cace154f2f2c64f2894b /pkg/gui/cherry_picking.go | |
parent | e290710f6741c046ee7e52e622af813e8955639b (diff) |
deal with the fact that a nil wrapped in an interface is not equal to nil
Diffstat (limited to 'pkg/gui/cherry_picking.go')
-rw-r--r-- | pkg/gui/cherry_picking.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go index e683d0f3f..1165a43a1 100644 --- a/pkg/gui/cherry_picking.go +++ b/pkg/gui/cherry_picking.go @@ -35,11 +35,12 @@ func (gui *Gui) handleCopyCommit() error { return err } - commit, ok := context.SelectedItem().(*commands.Commit) + item, ok := context.SelectedItem() if !ok { - gui.Log.Error("type cast failed for handling copy commit") + return nil } - if commit == nil { + commit, ok := item.(*commands.Commit) + if !ok { return nil } @@ -114,26 +115,24 @@ func (gui *Gui) handleCopyCommitRange() error { return err } - commit, ok := context.SelectedItem().(*commands.Commit) - if !ok { - gui.Log.Error("type cast failed for handling copy commit") - } - if commit == nil { + commitShaMap := gui.cherryPickedCommitShaMap() + commitsList := gui.commitsListForContext() + selectedLineIdx := context.GetPanelState().GetSelectedLineIdx() + + if selectedLineIdx > len(commitsList)-1 { return nil } - commitShaMap := gui.cherryPickedCommitShaMap() - // find the last commit that is copied that's above our position // if there are none, startIndex = 0 startIndex := 0 - for index, commit := range gui.commitsListForContext()[0:context.GetPanelState().GetSelectedLineIdx()] { + for index, commit := range commitsList[0:selectedLineIdx] { if commitShaMap[commit.Sha] { startIndex = index } } - for index := startIndex; index <= context.GetPanelState().GetSelectedLineIdx(); index++ { + for index := startIndex; index <= selectedLineIdx; index++ { gui.addCommitToCherryPickedCommits(index) } |