Skip to content

Commit

Permalink
fix: config.TryLoadRootConfig config detection (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki authored Feb 25, 2022
1 parent 677d3f0 commit c602e01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
23 changes: 23 additions & 0 deletions cmd/terramate/e2etests/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,26 @@ terramate {

assertRun(t, cli.run("stacks", "list", "--changed"))
}

func TestLoadGitRootConfig(t *testing.T) {
s := sandbox.NewWithGitConfig(t, sandbox.GitConfig{
DefaultRemoteName: "mineiros",
DefaultRemoteBranchName: "default",
LocalBranchName: "trunk",
})

cli := newCLI(t, s.RootDir())

test.WriteFile(t, s.RootDir(), "git.tm.hcl", `
terramate {
config {
git {
default_remote = "mineiros"
default_branch = "default"
}
}
}
`)

assertRun(t, cli.run("stacks", "list", "--changed"))
}
16 changes: 0 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package config

import (
"os"
"path/filepath"

"github.com/mineiros-io/terramate/hcl"
"github.com/rs/zerolog/log"
)
Expand All @@ -28,24 +25,11 @@ const (
)

func TryLoadRootConfig(dir string) (cfg hcl.Config, found bool, err error) {
path := filepath.Join(dir, DefaultFilename)
logger := log.With().
Str("action", "TryLoadRootConfig()").
Str("path", dir).
Str("configFile", path).
Logger()

logger.Trace().
Msg("Check if file exists.")
_, err = os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return hcl.Config{}, false, nil
}

return hcl.Config{}, false, err
}

logger.Trace().Msg("Parse Terramate config.")

cfg, err = hcl.ParseDir(dir)
Expand Down

0 comments on commit c602e01

Please sign in to comment.