1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Load defaults for AppState before reading from yaml

So far this hasn't been necessary because all defaults were zero values. We're
about to add the first non-zero value though, and it's important that it is
initialized correctly for users who have a state.yml that doesn't have it yet.
This commit is contained in:
Stefan Haller 2023-08-28 13:24:52 +02:00
parent 1106981827
commit f7db17f7d0

View File

@ -283,11 +283,13 @@ func (c *AppConfig) SaveAppState() error {
// loadAppState loads recorded AppState from file
func loadAppState() (*AppState, error) {
appState := getDefaultAppState()
filepath, err := configFilePath("state.yml")
if err != nil {
if os.IsPermission(err) {
// apparently when people have read-only permissions they prefer us to fail silently
return getDefaultAppState(), nil
return appState, nil
}
return nil, err
}
@ -298,10 +300,9 @@ func loadAppState() (*AppState, error) {
}
if len(appStateBytes) == 0 {
return getDefaultAppState(), nil
return appState, nil
}
appState := &AppState{}
err = yaml.Unmarshal(appStateBytes, appState)
if err != nil {
return nil, err