Skip to content

Commit

Permalink
Merge imported gossfiles in sorted order (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelsabbahy authored Sep 28, 2016
1 parent 00c6750 commit 46db773
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"reflect"
"sort"
"strings"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -92,8 +93,20 @@ func mergeJSONData(gossConfig GossConfig, depth int, path string) GossConfig {
fmt.Println("Error: Max depth of 50 reached, possibly due to dependency loop in goss file")
os.Exit(1)
}
// Our return gossConfig
ret := *NewGossConfig()
ret = mergeGoss(ret, gossConfig)

// Sort the gossfiles to ensure consistent ordering
var keys []string
for k, _ := range gossConfig.Gossfiles {
keys = append(keys, k)
}
sort.Strings(keys)

for _, g := range gossConfig.Gossfiles {
// Merge gossfiles in sorted order
for _, k := range keys {
g := gossConfig.Gossfiles[k]
var fpath string
if strings.HasPrefix(g.ID(), "/") {
fpath = g.ID()
Expand All @@ -102,9 +115,9 @@ func mergeJSONData(gossConfig GossConfig, depth int, path string) GossConfig {
}
fdir := filepath.Dir(fpath)
j := mergeJSONData(ReadJSON(fpath), depth, fdir)
gossConfig = mergeGoss(gossConfig, j)
ret = mergeGoss(ret, j)
}
return gossConfig
return ret
}

func WriteJSON(filePath string, gossConfig GossConfig) error {
Expand Down

0 comments on commit 46db773

Please sign in to comment.