Merge remote-tracking branch 'stevenwdv/merge-anchor-fix' into merge-anchor-fix

# Conflicts:
#	pkg/yqlib/doc/operators/anchor-and-alias-operators.md
#	pkg/yqlib/operator_anchors_aliases_test.go
This commit is contained in:
Steven WdV 2025-07-20 15:00:23 +02:00
commit 41cc4fb4ac
No known key found for this signature in database
3 changed files with 38 additions and 6 deletions

View File

@ -64,6 +64,38 @@ x: 1
y: 2
```
## Override
see https://yaml.org/type/merge.html
Given a sample.yml file of:
```yaml
- &CENTER
x: 1
y: 2
- &LEFT
x: 0
y: 2
- &BIG
r: 10
- &SMALL
r: 1
- !!merge <<:
- *BIG
- *LEFT
- *SMALL
x: 1
```
then
```bash
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
r: 10
y: 2
x: 1
```
## Get anchor
Given a sample.yml file of:
```yaml

View File

@ -304,7 +304,7 @@ foo_a
```
## Traversing merge anchors with override
This is legacy behavior, see --yaml-fix-merge-anchor-to-spec
This is legacy behaviour, see --yaml-fix-merge-anchor-to-spec
Given a sample.yml file of:
```yaml
@ -401,7 +401,7 @@ foobar_thing
```
## Traversing merge anchor lists
Note that the later merge anchors override previous, but this is legacy behavior, see --yaml-fix-merge-anchor-to-spec
Note that the later merge anchors override previous, but this is legacy behaviour, see --yaml-fix-merge-anchor-to-spec
Given a sample.yml file of:
```yaml
@ -434,7 +434,7 @@ bar_thing
```
## Splatting merge anchor lists
With legacy override behavior, see --yaml-fix-merge-anchor-to-spec
With legacy override behaviour, see --yaml-fix-merge-anchor-to-spec
Given a sample.yml file of:
```yaml

View File

@ -433,7 +433,7 @@ var traversePathOperatorScenarios = []expressionScenario{
},
{
description: "Traversing merge anchors with override",
subdescription: "This is legacy behavior, see --yaml-fix-merge-anchor-to-spec",
subdescription: "This is legacy behaviour, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobar.c`,
expected: []string{
@ -477,7 +477,7 @@ var traversePathOperatorScenarios = []expressionScenario{
{
description: "Traversing merge anchor lists",
subdescription: "Note that the later merge anchors override previous, " +
"but this is legacy behavior, see --yaml-fix-merge-anchor-to-spec",
"but this is legacy behaviour, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobarList.thing`,
expected: []string{
@ -502,7 +502,7 @@ var traversePathOperatorScenarios = []expressionScenario{
},
{
description: "Splatting merge anchor lists",
subdescription: "With legacy override behavior, see --yaml-fix-merge-anchor-to-spec",
subdescription: "With legacy override behaviour, see --yaml-fix-merge-anchor-to-spec",
document: mergeDocSample,
expression: `.foobarList[]`,
expected: []string{