From 9ec1b516c16f697fc0c3ae80b0d83f6d7270b5ed Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 18 Apr 2018 11:43:30 -0700 Subject: [PATCH] Handle cases in which there is no git repo data --- git/display.go | 4 ++++ git/widget.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/git/display.go b/git/display.go index be0b56f3..2e11edd4 100644 --- a/git/display.go +++ b/git/display.go @@ -10,6 +10,10 @@ func (widget *Widget) display() { widget.View.Clear() repoData := widget.currentData() + if repoData == nil { + fmt.Fprintf(widget.View, "%s", " Git repo data is unavailable (1)") + return + } title := fmt.Sprintf("[green]%s[white]\n", repoData.Repository) widget.View.SetTitle(fmt.Sprintf(" Git: %s ", title)) diff --git a/git/widget.go b/git/widget.go index 52bc6d08..55969baf 100644 --- a/git/widget.go +++ b/git/widget.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" @@ -78,7 +77,15 @@ func (widget *Widget) Prev() { /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) currentData() *GitRepo { - return widget.Data[widget.Idx] + if len(widget.Data) == 0 { + return nil + } + + if widget.Idx < 0 || widget.Idx >= len(widget.Data) { + return nil + } + + return widget.Data[widget.Idx] } func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {