fix: no reference nil deref error

Ayman Bagabas created

Change summary

go.mod                 | 2 +-
go.sum                 | 2 ++
ui/pages/repo/files.go | 3 +++
ui/pages/repo/log.go   | 6 ++++++
ui/pages/repo/refs.go  | 7 ++++++-
5 files changed, 18 insertions(+), 2 deletions(-)

Detailed changes

go.mod 🔗

@@ -5,7 +5,7 @@ go 1.17
 require (
 	github.com/alecthomas/chroma v0.10.0
 	github.com/caarlos0/env/v6 v6.9.1
-	github.com/charmbracelet/bubbles v0.10.4-0.20220429162018-2a8d463bd11f
+	github.com/charmbracelet/bubbles v0.10.4-0.20220524120539-e1871db6d35e
 	github.com/charmbracelet/bubbletea v0.20.0
 	github.com/charmbracelet/glamour v0.4.0
 	github.com/charmbracelet/lipgloss v0.4.0

go.sum 🔗

@@ -27,6 +27,8 @@ github.com/caarlos0/sshmarshal v0.0.0-20220308164159-9ddb9f83c6b3 h1:w2ANoiT4ubm
 github.com/caarlos0/sshmarshal v0.0.0-20220308164159-9ddb9f83c6b3/go.mod h1:7Pd/0mmq9x/JCzKauogNjSQEhivBclCQHfr9dlpDIyA=
 github.com/charmbracelet/bubbles v0.10.4-0.20220429162018-2a8d463bd11f h1:5mbyuBNzjF1S1pJOGubmjMBNUVO3NmjNsaZPIsFwPUQ=
 github.com/charmbracelet/bubbles v0.10.4-0.20220429162018-2a8d463bd11f/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
+github.com/charmbracelet/bubbles v0.10.4-0.20220524120539-e1871db6d35e h1:B+COqRjrl6G/X6v7salT4LDoSl+2Kz3g4OuDaoZCMwA=
+github.com/charmbracelet/bubbles v0.10.4-0.20220524120539-e1871db6d35e/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
 github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
 github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc=
 github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM=

ui/pages/repo/files.go 🔗

@@ -318,6 +318,9 @@ func (f *Files) StatusBarInfo() string {
 func (f *Files) updateFilesCmd() tea.Msg {
 	files := make([]selector.IdentifiableItem, 0)
 	dirs := make([]selector.IdentifiableItem, 0)
+	if f.ref == nil {
+		return common.ErrorMsg(errNoRef)
+	}
 	t, err := f.repo.Tree(f.ref, f.path)
 	if err != nil {
 		return common.ErrorMsg(err)

ui/pages/repo/log.go 🔗

@@ -302,6 +302,9 @@ func (l *Log) StatusBarInfo() string {
 }
 
 func (l *Log) countCommitsCmd() tea.Msg {
+	if l.ref == nil {
+		return common.ErrorMsg(errNoRef)
+	}
 	count, err := l.repo.CountCommits(l.ref)
 	if err != nil {
 		return common.ErrorMsg(err)
@@ -319,6 +322,9 @@ func (l *Log) updateCommitsCmd() tea.Msg {
 			count = int64(msg)
 		}
 	}
+	if l.ref == nil {
+		return common.ErrorMsg(errNoRef)
+	}
 	items := make([]selector.IdentifiableItem, count)
 	page := l.nextPage
 	limit := l.selector.PerPage()

ui/pages/repo/refs.go 🔗

@@ -1,6 +1,7 @@
 package repo
 
 import (
+	"errors"
 	"fmt"
 	"sort"
 	"strings"
@@ -14,6 +15,10 @@ import (
 	"github.com/charmbracelet/soft-serve/ui/git"
 )
 
+var (
+	errNoRef = errors.New("no reference specified")
+)
+
 // RefItemsMsg is a message that contains a list of RefItem.
 type RefItemsMsg struct {
 	prefix string
@@ -146,7 +151,7 @@ func (r *Refs) View() string {
 	return r.selector.View()
 }
 
-// StausBarValue implements statusbar.StatusBar.
+// StatusBarValue implements statusbar.StatusBar.
 func (r *Refs) StatusBarValue() string {
 	if r.activeRef == nil {
 		return ""