Bytes, not trees
Load a YAML file, set a value and write it back, and you rarely get the same file. Comments disappear, quotes move, the key order changes. In a merge request's diff it looks like a big change, although one version was meant.
pinup has a clear opinion here: a change is a byte range, not a tree.
01 — The opinion in one sentence
pinup replaces bytes at a known position and rewrites no file.
Every change in the plan names the file, the byte range, the bytes currently there, the new bytes and the manager that produced it.
{ "file": "compose.yaml", "start": 412, "end": 418,
"old": "0.29.0", "new": "0.30.1" }
Everything outside that range stays as it was: comments, indentation, quotes, line endings. That holds for a compose.yaml just as for your own .pinup.yaml.
02 — The alternative: editing the tree
In almost every language the natural path is a different one: parse the file, set the value in the tree, serialise the file. That is how yq -i, many scripts and many tools work. It is right where the tool owns the file itself, for instance generated configuration. Nobody minds a lost comment there.
Renovate, by the way, takes a path similar to pinup's in most places and replaces text. The difference lies elsewhere: in pinup the byte range with its expected content is part of the plan. The write phase cannot do anything but replace bytes.
03 — The price
Every manager must know positions. Finding a value is not enough. The manager has to say where it stands, to the byte, digests and multi-line values included.
Structural changes are hard. Putting a new key in the right place of a YAML file is tedious with byte ranges. So pinup avoids such changes where it can.
A check that rarely fires. If the expected bytes are not at the position, writing stops. Plan and write run in the same run on the same state. So the check mainly catches bugs in pinup itself, such as wrongly computed positions.
04 — The occasion
The real case is a composer.json. In my estate two managers read it: the Composer manager and a regex manager of my own for internal packages from the GitLab registry. Both find the same line. Both want to change it.
If both want the same, it is one change ordered twice. pinup writes it once. If they want different things, for instance because the two sources know different versions, tree editing would have decided silently: the second write overwrites the first, and the order determines the result.
With byte ranges it is a conflict you can see. Two changes claim the same bytes with different content. pinup names both and applies neither.
And your own configuration
pinup advise --fix corrects the configuration file itself. The rule applies there too. A commented .pinup.jsonc is still commented after the fix, and only the places of the corrections change. For a .pinup.yaml, advise names the correction, path and value, to make by hand until it can write YAML byte by byte as well. It is never re-serialised.
05 — The enforcement
- In the type. The stage that writes accepts only changes as byte ranges. It knows no dependency, no update and no version.
- At write time. Before every replacement pinup compares the bytes at the position with what it expects. If anything differs, the file changed since the plan, and nothing is written. All files are checked before the first one is written.
- In the lint. The YAML library may be imported in exactly one package. A test proves that the rule turns red when someone imports it elsewhere.
- In the tests. The golden tests compare the plan byte for byte. Another test applies the planned changes to a real repository, undoes them and expects the original file back byte for byte.
Frequently asked questions
Are comments in my .pinup.yaml preserved?+
Yes. pinup rewrites no file, its own configuration included. For updates that holds for every file. pinup advise --fix corrects a .pinup.jsonc or renovate.json byte by byte. For a .pinup.yaml it names the path and value of the correction to enter by hand.
What happens if I change the file between plan and run?+
Plan and write run in the same run on the same state. A change you push afterwards is seen by the next run. If the expected bytes still do not match for once, pinup writes nothing for that branch, not even halfway.
And lock files?+
They are the exception. A lock file cannot be updated through a byte range; it has to be regenerated. A task does that with the ecosystem's own tool, for instance Composer or npm. pinup checks its result against the files it may change.
Conclusion
A byte range is more work to produce than a tree. In return the diff shows exactly the version that changes, and a conflict is visible instead of silent. What is in your file stays your file.
Next week: where a value in the configuration comes from. The overview of all parts and the terms that recur are in the opening of the series.
Your merge requests change more than the version? I will find out why.
A look at your update merge requests and your managers: where files are rewritten, where two rules want the same line and how the diff gets small again.
About the author

Kai Ole Hartwig
Programming since 2002 – self-taught, set up my own business with KO-Web in 2012. Over 100 projects, with a focus on security, performance, automation and quality. Today freelance: DevSecOps consulting, training and software development.
Newsletter
The week, in one email.
The new advisories and posts, once a week and briefly put in context. You will get a confirmation email first, and opens and clicks are only counted anonymously.
Almost there – please confirm your subscription via the link in the email I have just sent you.
