Skip to content

Commit b97409e

Browse files
committed
bugfix: Navigate method didn't work with Windows-style paths
Fix arduino#150
1 parent 49d459e commit b97409e

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

Diff for: commands/root/root.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func initConfigs() {
126126
}
127127

128128
// Read configuration from global config file
129+
logrus.Info("Checking for config file in: " + commands.Config.ConfigFile.String())
129130
if commands.Config.ConfigFile.Exist() {
130131
readConfigFrom(commands.Config.ConfigFile)
131132
}
@@ -147,7 +148,7 @@ func initConfigs() {
147148
readConfigFrom(path)
148149
}
149150
} else {
150-
commands.Config.Navigate("/", pwd.String())
151+
commands.Config.Navigate(pwd)
151152
}
152153

153154
// Read configuration from old configuration file if found, but output a warning.

Diff for: configs/navigate.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@
1818
package configs
1919

2020
import (
21-
"path/filepath"
22-
"strings"
23-
2421
paths "github.com/arduino/go-paths-helper"
22+
"github.com/sirupsen/logrus"
2523
)
2624

27-
func (c *Configuration) Navigate(root, pwd string) {
28-
relativePath, err := filepath.Rel(root, pwd)
29-
if err != nil {
30-
return
31-
}
25+
func (c *Configuration) Navigate(pwd *paths.Path) {
26+
parents := pwd.Clean().Parents()
3227

3328
// From the root to the current folder, search for arduino-cli.yaml files
34-
parts := strings.Split(relativePath, string(filepath.Separator))
35-
for i := range parts {
36-
path := paths.New(root)
37-
path = path.Join(parts[:i+1]...)
38-
path = path.Join("arduino-cli.yaml")
39-
_ = c.LoadFromYAML(path)
29+
for i := range parents {
30+
path := parents[len(parents)-i-1].Join("arduino-cli.yaml")
31+
logrus.Info("Checking for config in: " + path.String())
32+
if err := c.LoadFromYAML(path); err != nil {
33+
logrus.WithError(err).Infof("error loading")
34+
}
4035
}
4136
}

Diff for: configs/navigate_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/arduino/arduino-cli/configs"
27+
paths "github.com/arduino/go-paths-helper"
2728
homedir "github.com/mitchellh/go-homedir"
2829
"github.com/sergi/go-diff/diffmatchpatch"
2930
)
@@ -36,13 +37,12 @@ func TestNavigate(t *testing.T) {
3637
}
3738
for _, tt := range tests {
3839
t.Run(tt, func(t *testing.T) {
39-
root := filepath.Join("testdata", "navigate", tt)
40-
pwd := filepath.Join("testdata", "navigate", tt, "first", "second")
40+
pwd := paths.New("testdata", "navigate", tt, "first", "second")
4141
golden := filepath.Join("testdata", "navigate", tt, "golden.yaml")
4242

4343
config, _ := configs.NewConfiguration()
4444

45-
config.Navigate(root, pwd)
45+
config.Navigate(pwd)
4646
data, _ := config.SerializeToYAML()
4747

4848
diff(t, data, golden)

0 commit comments

Comments
 (0)