From 4abd80e2c455cf7d92fa2b3a4389b5baa1ae5aa3 Mon Sep 17 00:00:00 2001 From: Moritz Haase Date: Sat, 26 Mar 2022 18:24:36 +0100 Subject: [PATCH] pkg/gui: Fix crash if auto-fetch interval is non-positive Check whether the auto-fetch interval configured is actually positive before starting the background fetcher. If it is not, an error is logged. Also improve the config option documentation a bit to make it easier to understand how to disable auto-fetch. --- docs/Config.md | 2 +- pkg/gui/gui.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 951686073..77685a378 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -86,7 +86,7 @@ os: openCommand: '' refresher: refreshInterval: 10 # File/submodule refresh interval in seconds. Auto-refresh can be disabled via option 'git.autoRefresh'. - fetchInterval: 60 # re-fetch interval in seconds + fetchInterval: 60 # Re-fetch interval in seconds. Auto-fetch can be disabled via option 'git.autoFetch'. update: method: prompt # can be: prompt | background | never days: 14 # how often an update is checked for diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 3848f2bd9..ba2d85a27 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -583,8 +583,16 @@ func (gui *Gui) Run(filterPath string) error { } gui.waitForIntro.Add(1) - if gui.c.UserConfig.Git.AutoFetch { - go utils.Safe(gui.startBackgroundFetch) + + if userConfig.Git.AutoFetch { + fetchInterval := userConfig.Refresher.FetchInterval + if fetchInterval > 0 { + go utils.Safe(gui.startBackgroundFetch) + } else { + gui.c.Log.Errorf( + "Value of config option 'refresher.fetchInterval' (%d) is invalid, disabling auto-fetch", + fetchInterval) + } } if userConfig.Git.AutoRefresh {