Skip to content

bugfix: Navigate method didn't work with Windows-style paths #154

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

Merged
merged 1 commit into from
Feb 22, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion commands/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func initConfigs() {
}

// Read configuration from global config file
logrus.Info("Checking for config file in: " + commands.Config.ConfigFile.String())
if commands.Config.ConfigFile.Exist() {
readConfigFrom(commands.Config.ConfigFile)
}
Expand All @@ -147,7 +148,7 @@ func initConfigs() {
readConfigFrom(path)
}
} else {
commands.Config.Navigate("/", pwd.String())
commands.Config.Navigate(pwd)
}

// Read configuration from old configuration file if found, but output a warning.
Expand Down
23 changes: 9 additions & 14 deletions configs/navigate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,19 @@
package configs

import (
"path/filepath"
"strings"

paths "github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

func (c *Configuration) Navigate(root, pwd string) {
relativePath, err := filepath.Rel(root, pwd)
if err != nil {
return
}
func (c *Configuration) Navigate(pwd *paths.Path) {
parents := pwd.Clean().Parents()

// From the root to the current folder, search for arduino-cli.yaml files
parts := strings.Split(relativePath, string(filepath.Separator))
for i := range parts {
path := paths.New(root)
path = path.Join(parts[:i+1]...)
path = path.Join("arduino-cli.yaml")
_ = c.LoadFromYAML(path)
for i := range parents {
path := parents[len(parents)-i-1].Join("arduino-cli.yaml")
logrus.Info("Checking for config in: " + path.String())
if err := c.LoadFromYAML(path); err != nil {
logrus.WithError(err).Infof("error loading")
}
}
}
6 changes: 3 additions & 3 deletions configs/navigate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/arduino/arduino-cli/configs"
paths "github.com/arduino/go-paths-helper"
homedir "github.com/mitchellh/go-homedir"
"github.com/sergi/go-diff/diffmatchpatch"
)
Expand All @@ -36,13 +37,12 @@ func TestNavigate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt, func(t *testing.T) {
root := filepath.Join("testdata", "navigate", tt)
pwd := filepath.Join("testdata", "navigate", tt, "first", "second")
pwd := paths.New("testdata", "navigate", tt, "first", "second")
golden := filepath.Join("testdata", "navigate", tt, "golden.yaml")

config, _ := configs.NewConfiguration()

config.Navigate(root, pwd)
config.Navigate(pwd)
data, _ := config.SerializeToYAML()

diff(t, data, golden)
Expand Down