diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 57a8562..0378328 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,4 +23,4 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3.4.0 with: - version: v1.52 + version: v1.54 diff --git a/pkg/config/config.go b/pkg/config/config.go index cda69d8..72e0366 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -213,6 +213,7 @@ func load(generalFilePath, hostsFilePath string, fallback *Config) (*Config, err if hostsMap != nil && !hostsMap.Empty() { generalMap.AddEntry("hosts", hostsMap) + generalMap.SetUnmodified() } if generalMap.Empty() && fallback != nil { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 03fdf06..32d04c1 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestConfigDir(t *testing.T) { @@ -624,6 +625,27 @@ func TestSet(t *testing.T) { } } +func TestEntriesShouldBeModifiedOnLoad(t *testing.T) { + // Given we have a persisted config and hosts file + tempDir := t.TempDir() + t.Setenv("GH_CONFIG_DIR", tempDir) + + require.NoError(t, writeFile(hostsConfigFile(), []byte(testHostsData()))) + require.NoError(t, writeFile(generalConfigFile(), []byte(testGlobalData()))) + + // When we load that config + cfg, err := load(generalConfigFile(), hostsConfigFile(), nil) + require.NoError(t, err) + + // Then the general and host entries should be unmodified + // because we didn't mutate anything yet + require.False(t, cfg.entries.IsModified()) + + hosts, err := cfg.entries.FindEntry("hosts") + require.NoError(t, err) + require.False(t, hosts.IsModified()) +} + func testConfig() *Config { var data = ` git_protocol: ssh