Repository: jesseduffield/lazygit (language: go)

Issue:
panic: non-positive interval for NewTicker
**Describe the bug**
Since a few weeks (without updating lazygit itself), I get the following error when starting lazygit from the shell:

panic: non-positive interval for NewTicker

goroutine 11 [running]:
time.NewTicker(0x0, 0x0)
	/opt/homebrew/Cellar/go/1.16.4/libexec/src/time/tick.go:24 +0x144
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).goEvery.func1()
	/private/tmp/lazygit-20210604-23703-e7fn5f/lazygit-0.28.2/pkg/gui/gui.go:697 +0x4c
github.com/jesseduffield/lazygit/pkg/utils.Safe.func1(0x0, 0x0)
	/private/tmp/lazygit-20210604-23703-e7fn5f/lazygit-0.28.2/pkg/utils/utils.go:107 +0x28
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0x140002727b8, 0x0, 0x0)
	/private/tmp/lazygit-20210604-23703-e7fn5f/lazygit-0.28.2/pkg/utils/utils.go:118 +0x5c
github.com/jesseduffield/lazygit/pkg/utils.Safe(0x14000079050)
	/private/tmp/lazygit-20210604-23703-e7fn5f/lazygit-0.28.2/pkg/utils/utils.go:107 +0x40
created by github.com/jesseduffield/lazygit/pkg/gui.(*Gui).goEvery
	/private/tmp/lazygit-20210604-23703-e7fn5f/lazygit-0.28.2/pkg/gui/gui.go:696 +0x88

**Desktop (please complete the following information):**
 - OS: OSX 11.5.1, M1 Macbook Pro, Homebrew
 - Lazygit Version 0.28.2 via homebrew



Thank You for your help!


Discussion / hints:
Can you share your lazygit config?  
Thank You, you pointed me to the right direction:

I changed:

```
refreshInterval: 0 #10 # file/submodule refresh interval in seconds
fetchInterval: 0 #60 # re-fetch interval in seconds
```

Changing these back to 10 and 60 did the trick.

Best regards, 
Ralf.
Great you fixed the problem and thanks for pointing out the fields that where the problem.
What did you expect to happen when you set your config to 0?, i'm thinking of 2 things that could happen:
- Fallback to the default value if 0 is set
- Disable this interval
I was having problems when reviewing code changes. The viewport jumps to the top of the page when time interval of refresh is reached. I tried to disable automatic refresh completely. 
I also want to disable automatic refresh completely. @jesseduffield please implement this so 0 means to disable it.
I’m not using lazygit yet because of this. I just hate when automatically run things want to use my ssh key and a windows pops up on my screen asking me to unlock it without me having any context what it will be used for.
Thanks!
@henkworks Auto fetching can be disabled by setting the `autoFetch` option in the config file to `false`.

```
git:                                                                                                
  autoFetch: false
```
@jesseduffield Would it make sense to check whether `fetchInterval` is not `0` (when `autoFetch` is `true`) before enabling the background fetch? Also, I could have a go at implementing support to disable the file refresh via `refreshInterval: 0` if you think that's a good idea.
> @henkworks Auto fetching can be disabled by setting the `autoFetch` option in the config file to `false`.
> 
> ```
> git:                                                                                                
>   autoFetch: false
> ```

Thank you very much, that helps with my main concern!

The issue this bug is about is still present with that setting though, as long as the following is in the config, it seems:
```
refresher:
  refreshInterval: 0
```
produces:
```
± ~/go/bin/lazygit
panic: non-positive interval for NewTicker

goroutine 18 [running]:
time.NewTicker(0x0, 0x4db02f)
        /usr/lib/go-1.15/src/time/tick.go:23 +0x151
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).goEvery.func1()
        /home/henk/Data/public/software/lazygit/pkg/gui/gui.go:692 +0x67
github.com/jesseduffield/lazygit/pkg/utils.Safe.func1(0xc0001e6840, 0xc0000437b0)
        /home/henk/Data/public/software/lazygit/pkg/utils/utils.go:95 +0x24
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0xc0000437b8, 0x0, 0x0)
        /home/henk/Data/public/software/lazygit/pkg/utils/utils.go:106 +0x62
github.com/jesseduffield/lazygit/pkg/utils.Safe(0xc000090600)
        /home/henk/Data/public/software/lazygit/pkg/utils/utils.go:95 +0x49
created by github.com/jesseduffield/lazygit/pkg/gui.(*Gui).goEvery
        /home/henk/Data/public/software/lazygit/pkg/gui/gui.go:691 +0x8a
[2]    1585044 exit 2     ~/go/bin/lazygit
```
@moha-gh Using zero to mean 'never' isn't directly obvious, however I don't think we can use `false` in a field that's meant to be a number. So if we document it properly then I think zero is good enough.
actually how about we add an 'autoRefresh' key similar to 'autoFetch'? That would be far more explicit

Fix patch:
diff --git a/docs/Config.md b/docs/Config.md
index aac7f034909..77685a3789d 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -73,6 +73,7 @@ git:
     showGraph: 'when-maximised'
   skipHookPrefix: WIP
   autoFetch: true
+  autoRefresh: true
   branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'
   allBranchesLogCmd: 'git log --graph --all --color=always --abbrev-commit --decorate --date=relative  --pretty=medium'
   overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
@@ -84,8 +85,8 @@ os:
   editCommandTemplate: '{{editor}} {{filename}}'
   openCommand: ''
 refresher:
-  refreshInterval: 10 # file/submodule refresh interval in seconds
-  fetchInterval: 60 # re-fetch interval in seconds
+  refreshInterval: 10 # File/submodule refresh interval in seconds. Auto-refresh can be disabled via option 'git.autoRefresh'.
+  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/config/user_config.go b/pkg/config/user_config.go
index 988673f1eea..321a7fa5efb 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -68,6 +68,7 @@ type GitConfig struct {
 	Merging             MergingConfig                 `yaml:"merging"`
 	SkipHookPrefix      string                        `yaml:"skipHookPrefix"`
 	AutoFetch           bool                          `yaml:"autoFetch"`
+	AutoRefresh         bool                          `yaml:"autoRefresh"`
 	BranchLogCmd        string                        `yaml:"branchLogCmd"`
 	AllBranchesLogCmd   string                        `yaml:"allBranchesLogCmd"`
 	OverrideGpg         bool                          `yaml:"overrideGpg"`
@@ -373,6 +374,7 @@ func GetDefaultConfig() *UserConfig {
 			},
 			SkipHookPrefix:      "WIP",
 			AutoFetch:           true,
+			AutoRefresh:         true,
 			BranchLogCmd:        "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
 			AllBranchesLogCmd:   "git log --graph --all --color=always --abbrev-commit --decorate --date=relative  --pretty=medium",
 			DisableForcePushing: false,
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index b4e0f8de488..ba2d85a2750 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -583,11 +583,28 @@ 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)
+		}
 	}
 
-	gui.goEvery(time.Second*time.Duration(userConfig.Refresher.RefreshInterval), gui.stopChan, gui.refreshFilesAndSubmodules)
+	if userConfig.Git.AutoRefresh {
+		refreshInterval := userConfig.Refresher.RefreshInterval
+		if refreshInterval > 0 {
+			gui.goEvery(time.Second*time.Duration(refreshInterval), gui.stopChan, gui.refreshFilesAndSubmodules)
+		} else {
+			gui.c.Log.Errorf(
+				"Value of config option 'refresher.refreshInterval' (%d) is invalid, disabling auto-refresh",
+				refreshInterval)
+		}
+	}
 
 	gui.c.Log.Info("starting main loop")
 


Test patch: