Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config should load as unmodified #147

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped this because it seemed to resolve some linting errors. cli/cli is already on 1.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