Add !merge tag for positional sequence merge - #900
Draft
ndeloof wants to merge 1 commit into
Draft
Conversation
Sequences are otherwise always appended (or fully replaced) when merging an
override file, so there is no way to change a single element of a list
in-place. The new `!merge` tag, applicable to a sequence in an override file
(ignored elsewhere), merges the sequence element by element by index instead:
- a no-op element (`- {}` or `- null`) leaves the base element untouched, so an
override can target one element while keeping the others;
- any other element is deep-merged with the base element at the same index
(deep-merge for mappings, replace for scalars);
- length mismatches extend or preserve the tail as expected.
The loader (ResetProcessor) records the paths of `!merge`-tagged sequences and
strips the tag, then override.MergeWithPositionalPaths performs the positional
merge at those paths — taking precedence over the default append and the
per-field merge rules, since it is an explicit user request. The default
behavior is unchanged when the tag is absent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Prototype / draft for discussion.
What
Add a
!mergeYAML tag that makes an override sequence merge positionally(element by element, by index) instead of the default append.
Today sequences can only be appended (default /
mergeToSequence) or fullyreplaced (
!override, or theoverriderule forcommand/entrypoint/…).There is no way to change a single element of a list in place.
!mergefillsthat gap:
Semantics, per index
i:- {}or- null) keepsbase[i];override[i]is deep-merged withbase[i](deep-merge formappings, replace for scalars);
The tag is ignored on anything that is not a sequence, and the default
behavior is unchanged when the tag is absent (opt-in, non-breaking).
!mergetakes precedence over both the default append and the per-field merge rules,
since it is an explicit user request.
How
Mirrors the existing
!reset/!overridemachinery:loader/reset.go—ResetProcessorrecords the paths of!merge-taggedsequences and strips the tag so the node decodes as a plain sequence.
loader/loader.go— passes those paths to the merge step.override/merge.go— newMergeWithPositionalPaths/mergePositionalperforms the positional merge at the recorded paths.
Merge/MergeYamlstayas-is (wrappers), so the public API is unchanged.
Tests double as documentation:
override/merge_positional_test.go(semantics)and
loader/merge_positional_test.go(the tag end to end).Known limitations (prototype)
build,networks,depends_on, …), so a!mergenested under one of those fieldsis not honored yet.
!mergesequence reused through a YAML anchor is not cached/replayed at thereuse site.
Both are addressable follow-ups if the approach is accepted.
🤖 Generated with Claude Code