Skip to content

Commit

Permalink
Merge pull request #147 from cli/wm/entries-should-load-unmodified
Browse files Browse the repository at this point in the history
Config should load as unmodified
  • Loading branch information
williammartin authored Jan 23, 2024
2 parents d32c104 + 25d7c84 commit d88d88f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3.4.0
with:
version: v1.52
version: v1.54
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestConfigDir(t *testing.T) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d88d88f

Please sign in to comment.