@@ -282,9 +282,20 @@ func (p Product) Lineage() string {
282282 return p .Name
283283}
284284
285- func Merge (self , otherObj reflect.Value ) {
286-
285+ func Merge (self , otherObj reflect.Value , version string ) {
287286 selfObj := reflect .Indirect (self )
287+
288+ // Skip merge if otherObj targets a higher version than what is being generated
289+ for i := 0 ; i < otherObj .NumField (); i ++ {
290+ if otherObj .Type ().Field (i ).Name == "MinVersion" {
291+ for j := slices .Index (product .ORDER , version ) + 1 ; j < len (product .ORDER ); j ++ {
292+ if otherObj .Field (i ).String () == product .ORDER [j ] {
293+ return
294+ }
295+ }
296+ }
297+ }
298+
288299 for i := 0 ; i < selfObj .NumField (); i ++ {
289300
290301 // skip if the override is the "empty" value
@@ -295,14 +306,14 @@ func Merge(self, otherObj reflect.Value) {
295306 }
296307
297308 if selfObj .Field (i ).Kind () == reflect .Slice {
298- DeepMerge (selfObj .Field (i ), otherObj .Field (i ))
309+ DeepMerge (selfObj .Field (i ), otherObj .Field (i ), version )
299310 } else {
300311 selfObj .Field (i ).Set (otherObj .Field (i ))
301312 }
302313 }
303314}
304315
305- func DeepMerge (arr1 , arr2 reflect.Value ) {
316+ func DeepMerge (arr1 , arr2 reflect.Value , version string ) {
306317 if arr1 .Len () == 0 {
307318 arr1 .Set (arr2 )
308319 return
@@ -341,7 +352,7 @@ func DeepMerge(arr1, arr2 reflect.Value) {
341352 }
342353 }
343354 if otherVal .IsValid () {
344- Merge (currentVal , otherVal )
355+ Merge (currentVal , otherVal , version )
345356 }
346357 }
347358
0 commit comments