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

fix(updating): exclude deleted paths on update #1719

Merged
merged 6 commits into from
Aug 17, 2024

Conversation

lkubb
Copy link
Contributor

@lkubb lkubb commented Aug 1, 2024

Previously, paths that matched a pattern in skip_if_exists and that were deleted in the generated project were recreated during each update.

These deletions are contained in the diff between old vanilla generated project and the (pre-update) current one. They are not executed though since the paths are excluded from the diff application.

Previously, if a file that was deleted intentionally in a generated project was changed in the template, an update would have regenerated it (but not if it did not have any changes).

This patch ensures that update behavior is consistent for paths that are not listed in skip_if_exists - don't regenerate deleted paths during update - by acquiring a list of deleted paths and excluding them in the copy operations that are relevant for acquiring the update diff. skip_if_exists paths are not excluded, their presence is always ensured, even by copier update (#1718 (comment)).

Fixes: #1721

Thanks a lot for maintaining this very neat tool btw!

@lkubb lkubb force-pushed the fix/skip-if-exists-update branch 2 times, most recently from a27a19f to f44d4af Compare August 1, 2024 01:04
@lkubb lkubb marked this pull request as ready for review August 1, 2024 01:15
@lkubb lkubb force-pushed the fix/skip-if-exists-update branch from f44d4af to 7eb29ad Compare August 1, 2024 09:45
@sisp
Copy link
Member

sisp commented Aug 4, 2024

Thanks for raising this problem and offering a PR to fix it, @lkubb! 🙏

I wonder whether we could take a different approach involving programmatic use of exclude to avoid unnecessarily re-creating files in the first place rather than deleting re-created files as a post-processing step. Similar to your current implementation, we need to determine which files in the skip_if_exists list have been deleted by the user. But if we moved building this list above overwriting the subproject with the new template version, then we could pass it via the exclude argument to that worker and also to the worker creating a fresh copy with the new template version. As a results, the diff should not contain files from skip_if_exists, as they don't get created at all.

I haven't tested this idea, so I might have overlooked something.

WDYT, @lkubb?

@lkubb
Copy link
Contributor Author

lkubb commented Aug 4, 2024

Thanks for raising this problem and offering a PR to fix it, @lkubb! 🙏

@sisp Thanks for taking the time to consider my proposal. :) Responding to your issue comment caused me to find another related inconsistency (imho), #1721.

I wonder whether we could take a different approach involving programmatic use of exclude to avoid unnecessarily re-creating files in the first place rather than deleting re-created files as a post-processing step.

Your proposal additionally allows to fix #1721 elegantly by excluding all deleted paths (if solution (a) from the issue is deemed acceptable).

I haven't tested this idea, so I might have overlooked something.

An issue I can see with your proposal in comparison to mine is that tasks (not migrations, here it's an issue for both) might assume the presence of a specific file, but that's common to all exclude usage.

I will implement your proposal as described above, fixing the new issue as well. Happy to iterate on this if there is some disagreement. Thanks again for your time!

@lkubb lkubb force-pushed the fix/skip-if-exists-update branch 2 times, most recently from ef99f7f to 0780374 Compare August 4, 2024 14:50
Previously, paths that matched a pattern in `skip_if_exists` and that
were deleted in the generated project were recreated during each update.

These deletions are contained in the diff between old vanilla generated
project and the (pre-update) current one. They are not executed though
since the paths are excluded from the diff application.

Similarly, if a file that was deleted intentionally in a generated
project was changed in the template, an update would have regenerated
it (but not if it did not have any changes). I'm not completely sure how
this manifested, but it probably involved a suppressed merge conflict.

This commit ensures that update behavior is always consistent -
never regenerate deleted paths during `update` - by acquiring a list of
deleted paths and excluding them in the copy operations that are
relevant for acquiring the update diff.
@lkubb lkubb force-pushed the fix/skip-if-exists-update branch from 0780374 to 30ad622 Compare August 4, 2024 14:52
@lkubb lkubb changed the title fix(updating): do not recreate deleted paths in skip_if_exists on update fix(updating): never recreate deleted paths on update Aug 4, 2024
Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.61%. Comparing base (6fd3ad4) to head (2150516).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1719      +/-   ##
==========================================
- Coverage   97.71%   97.61%   -0.10%     
==========================================
  Files          49       49              
  Lines        4980     5042      +62     
==========================================
+ Hits         4866     4922      +56     
- Misses        114      120       +6     
Flag Coverage Δ
unittests 97.61% <100.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few minor remarks, and we need to escape the file names to be excluded (see inline comment).

copier/main.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I reviewed the PR before the issues (my fault).

Let's triage the issues first. I'm not yet convinced they're bugs. Thanks!

@lkubb lkubb changed the title fix(updating): never recreate deleted paths on update fix(updating): exclude deleted paths on update Aug 12, 2024
Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks excellent!

Would you please remove those references to issues, so I can merge?

copier/main.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
tests/test_updatediff.py Outdated Show resolved Hide resolved
@lkubb lkubb requested a review from yajo August 16, 2024 12:58
@yajo yajo enabled auto-merge (squash) August 16, 2024 18:13
@yajo yajo mentioned this pull request Aug 16, 2024
@lkubb lkubb requested a review from sisp August 16, 2024 18:38
Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, @lkubb, thanks! 👌

And thanks for taking over, @yajo; I have been on vacation.

@yajo yajo merged commit 5ac93ee into copier-org:master Aug 17, 2024
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent update behavior when a generated file was deleted
3 participants