geofffranks / spruce

A BOSH template merge tool
MIT License
426 stars 77 forks source link

Possible Bug? Unexpected behavior when merging array of maps #375

Closed HackXIt closed 1 year ago

HackXIt commented 1 year ago

I downloaded the latest version of spruce (v1.30.2) on windows and I'm running into weird behavior.

I'm fairly new to using spruce, so I've been going off from the documentation directly.

The problem: When executing spruce merge .\base.yml .\file1.yml .\file2.yml, I get an array, where the first element always gets overwritten, instead of being appended, even though I specifically added (( merge on get )). According to doc/array-merging, it is supposed to change the identifier that is used to determine if an element already exists and should be overwritten or if it is a new element.

These are my test files: base.yml

---
plan:
  - (( merge on get ))

file1.yml

---
plan:
  - get: file1
    params:
      depth: 1
    trigger: false

file2.yml

---
plan:
  - get: file2
    params:
      depth: 1
    trigger: false

It works as expected when I change the key get to name. It seems to me as if my provided operator in base.yml is simply ignored.

Output when using get as identifier:

plan:
- get: file2
  params:
    depth: 1
  trigger: false

Output when changing file1 and file2 to use name as identifier:

plan:
- name: file1
  params:
    depth: 1
  trigger: false
- name: file2
  params:
    depth: 1
  trigger: false

In both cases I left base.yml as is, with the (( merge on get )) operator placed.

HackXIt commented 1 year ago

Ok, in an attempt to figure it out, I added (( merge on get )) to both file1 and file2. Now it works as intended.

It was not clear from the documentation that every file that is going to be merge needs to have that operator placed. I'm unsure if that's expected or if it's faulty behaviour.

Any help or pinpointing to where it says that in the documentation would be greatly appreciated.