@@ -22,7 +22,9 @@ import (
22
22
// Always runs in strict mode: type mismatches or duplicate keys cause an error.
23
23
func Merge (inputs [][]byte ) (* bytes.Buffer , error ) {
24
24
var merged any
25
+
25
26
hasContent := false
27
+
26
28
for idx , data := range inputs {
27
29
dec := yaml .NewDecoder (bytes .NewReader (data ), yaml .UseOrderedMap (), yaml .Strict ())
28
30
@@ -31,8 +33,10 @@ func Merge(inputs [][]byte) (*bytes.Buffer, error) {
31
33
if errors .Is (err , io .EOF ) {
32
34
continue
33
35
}
36
+
34
37
return nil , fmt .Errorf ("decoding document %d: %s" , idx , yaml .FormatError (err , false , false ))
35
38
}
39
+
36
40
hasContent = true
37
41
38
42
mergedValue , err := mergeValue (merged , value )
@@ -91,8 +95,10 @@ func mergeValue(into, from any) (any, error) {
91
95
func mergeMap (into , from yaml.MapSlice ) (yaml.MapSlice , error ) {
92
96
out := make (yaml.MapSlice , len (into ))
93
97
copy (out , into )
98
+
94
99
for _ , item := range from {
95
100
matched := false
101
+
96
102
for i , existing := range out {
97
103
if ! reflect .DeepEqual (existing .Key , item .Key ) {
98
104
continue
@@ -102,13 +108,16 @@ func mergeMap(into, from yaml.MapSlice) (yaml.MapSlice, error) {
102
108
if err != nil {
103
109
return nil , err
104
110
}
111
+
105
112
out [i ].Value = mergedVal
106
113
matched = true
107
114
}
115
+
108
116
if ! matched {
109
117
out = append (out , yaml.MapItem {Key : item .Key , Value : item .Value })
110
118
}
111
119
}
120
+
112
121
return out , nil
113
122
}
114
123
@@ -126,8 +135,10 @@ func describe(i any) string {
126
135
if isMapping (i ) {
127
136
return "mapping"
128
137
}
138
+
129
139
if isSequence (i ) {
130
140
return "sequence"
131
141
}
142
+
132
143
return "scalar"
133
144
}
0 commit comments