feat(update): preserve developer-owned regions across updates (#2184)#2762
Open
DrKat0m wants to merge 3 commits into
Open
feat(update): preserve developer-owned regions across updates (#2184)#2762DrKat0m wants to merge 3 commits into
DrKat0m wants to merge 3 commits into
Conversation
…-org#2184) Templates often ship files with dummy content or TODO markers that the developer replaces right after generation. Previously `copier update` treated those regions like any other template-owned content, so a change to the placeholder in the template could clobber the developer's work or raise a needless merge conflict. Template authors can now wrap a developer-owned region in literal marker comments that survive rendering: # copier:preserve:start <optional-id> ...developer-owned content... # copier:preserve:end <optional-id> During an update the content between the markers is captured from the current project and injected into every intermediate render (old render, new render, and the freshly rendered destination) so all three merge sides agree on the region. The merge therefore keeps the developer's content conflict-free, while the marker lines and surrounding content keep updating from the template as usual. - Added `copier/_preserve.py` with the marker parsing, capture and restore primitives. - Wired capture/restore into `Worker._apply_update`, scoping the scan to template-managed files discovered in the old render. - Documented the feature in `docs/updating.md`. - Added unit and integration tests in `tests/test_preserve.py`.
Contributor
Author
|
Hi @sisp, whenever you have a chance, could you please take a look at this PR? I'd really appreciate any feedback on the approach (especially the choice to keep the region conflict free by aligning all three merge sides rather than post processing conflict output) and on the marker syntax. Happy to iterate on anything. Thank you! |
`test_tools.py::test_types` runs `mypy .` over the whole tree and flagged three `_apply_regions` calls in `tests/test_preserve.py`: the local dicts were inferred as `dict[str, str]`, which is not assignable to the expected `dict[_RegionKey, str]` because `dict` is invariant in its key type. Annotate the three test dicts with `_RegionKey` so they match the parameter type.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2762 +/- ##
==========================================
- Coverage 97.29% 97.16% -0.13%
==========================================
Files 60 62 +2
Lines 7584 7808 +224
==========================================
+ Hits 7379 7587 +208
- Misses 205 221 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Templates often ship files with dummy content or TODO markers that the developer replaces right after generation. Previously
copier updatetreated those regions like any other template-owned content, so a change to the placeholder in the template could clobber the developer's work or raise a needless merge conflict.Template authors can now wrap a developer-owned region in literal marker comments that survive rendering:
During an update the content between the markers is captured from the current project and injected into every intermediate render (old render, new render, and the freshly rendered destination) so all three merge sides agree on the region. The merge therefore keeps the developer's content conflict-free, while the marker lines and surrounding content keep updating from the template as usual.
copier/_preserve.pywith the marker parsing, capture and restore primitives.Worker._apply_update, scoping the scan to template-managed files discovered in the old render.docs/updating.md.tests/test_preserve.py.Closes #2184