Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Merge new fields only" is missing comments #2201

Open
jandubois opened this issue Nov 20, 2024 · 2 comments
Open

"Merge new fields only" is missing comments #2201

jandubois opened this issue Nov 20, 2024 · 2 comments
Labels

Comments

@jandubois
Copy link
Contributor

I'm trying to merge 2 data files, but only want to merge keys from the second file that don't exist in the first. I expect that all comments on copied keys are merged as well.

Version of yq: 4.44.3
Operating system: macOS 12.7.6 (Monterey)
Installed via: homebrew

Input Yamls

empty.yaml:

empty: true

comments.yaml:

# foo head comment
foo: 1 # foo line comment

# bar head comment
bar: # bar line comment
  # baz head comment
  baz: # baz line comment
    # yolo head comment
    yolo: 2 # yolo line comment

Command

yq eval-all -n 'load("empty.yaml") *n load("comments.yaml")'

Actual behavior

empty: true
foo: 1 # foo line comment
bar:
  baz:
    yolo: 2 # yolo line comment

Expected behavior

I expected all the comments to be merged as well. Since none of the fields in comments.yaml exist in empty.yaml the result of *n to be identical to *:

yq eval-all -n 'load("empty.yaml") * load("comments.yaml")'
empty: true
# foo head comment
foo: 1 # foo line comment
# bar head comment
bar: # bar line comment
  # baz head comment
  baz: # baz line comment
    # yolo head comment
    yolo: 2 # yolo line comment
@jandubois
Copy link
Contributor Author

It looks like the comments attached to the keys are not copied over, probably because they are auto-created when the values are copied.

@jandubois jandubois changed the title Merge new fields only is missing comments "Merge new fields only" is missing comments Nov 22, 2024
@mikefarah
Copy link
Owner

Yep, you are right. I'll need to find spare time to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants