-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
skip_if_exists
interaction with deleted files on update
#1718
Comments
Thanks for raising this problem, @lkubb! 🙏 I left a comment in your PR with an alternative implementation idea. But I've also been thinking about the meaning and expected behavior of If you want to delete a file that is listed in WDYT? |
@sisp Thank you! I'm currently looking into your proposal.
This would be one example. Another one, which the above-mentioned template intends to do, is to generate example code which should always be amended in the final project.
I'm only proposing to align the Edit:
This would break the example file use case I described above.
I like this proposal in general since it is project-specific configuration, just not as a workaround for this behavior. Copier not remembering those after project generation is something that came up while writing Renovate support for Copier (renovatebot/renovate#25538 (comment), see details at the bottom). |
I'm not sure this is a bug. ˋskip_if_existsˋ shouldn't skip if it doesn't exist (obviously). If it did, that'd be a bug. One use case is when the data you supply is just a foolish bootstrapping template that you expect the user will change a lot and those changes won't have any importance for the template itself. Another use case is when dumping out secrets. Those questions won't be stored on copier-answers, so the next update won't know the previous one's secrets. Usually these files are written in a non-git-tracked path. If they exist, you probably already wrote those secrets, so we just skip them. What you really want is ˋexcludeˋ, which really excludes the thing. Or, probably, just don't add it to ˋskip_if_existsˋ, and IIUC copier won't recreate it unless changed in the template. |
I agree for the Which problems does the current behavior of always recreating the file on update solve (if it's intentional)? And why should it be different for files that are not listed there? (Edit: If this is intentional, #1725 is what I would have expected from
In essence, this is why this behavior stumped me. I'm not saying the mentioned template is just a "foolish" bootstrapping template, but it has these bootstrapping parts. Different Salt module types have different predefined required methods (they are not changing). It helps to have an initial template that can be filled by users, but they can add more than one module of the same type or name it differently.
Not adding it to When examples can have small changes from time to time, there are several issues with
|
So, the whole point of this is: what should copier do if one file listed to skip if exists happens to be deleted in the subproject but changed in the template? Should it behave like if it were listed in exclude? (What you propose) Or should it behave as a merge conflict and write the file? (Current behavior) IMHO current behavior is correct because the option is called "skip if exists", not "skip if updating". The fact is it doesn't exist, so it shouldn't be skipped. This behavior is the same for any other file under the same circumstances. However then the next question is: how to give you the power to have a "skip if updating"? 😉 I think we could simply add a |
Closing as duplicate of #1725. |
Thanks, your proposal would provide a way to do what I initially wanted. Just some comments:
My proposal was to make the update behavior of deleted files consistent. Additionally, I think all project-deleted files should be excluded during The current
The current behavior does not report a merge conflict though.
I agree with the linguistic logic, but imho it's surprising that a switch named "skip if exists" increases the likelihood of a file to be recreated. This should be documented. I'm still not sure which problem this behavior solves though, the code seemed like it was unintentional. |
Describe the problem
When a path that is affected by
skip_if_exists
is deleted in a generated project, an update regenerates it anyways.Template
https://github.com/salt-extensions/salt-extension-copier (sadly requires
--trust
, but this could be reproduced easily with a simple demo template)To Reproduce
copier copy --trust --defaults --data project_name=foo --data author='Foo Bar' --data author_email='[email protected]' https://github.com/salt-extensions/salt-extension-copier foo
cd foo; git init && git add . && git commit -m "initial commit"
rm tests/functional/modules/test_foo.py && git commit -am rm
copier update --trust --skip-answered
git status
[shows new, untrackedtests/functional/modules/test_foo.py
]Logs
No response
Expected behavior
The path to stay absent if it was deleted after project generation, as it's usually the case.
Screenshots/screencasts/logs
No response
Operating system
macOS
Operating system distribution and version
14.6
Copier version
copier 9.1.0
Python version
CPython 3.11
Installation method
pipx+pypi
Additional context
The following code recreates the already deleted file:
copier/copier/main.py
Lines 954 to 963 in 6fd3ad4
The diff contains the deleted file, it would be removed usually:
copier/copier/main.py
Lines 1006 to 1010 in 6fd3ad4
But
git apply
is told to ignore changes to it, hence it remains:copier/copier/main.py
Lines 1029 to 1033 in 6fd3ad4
A solution could be to:
--diff-filter=D
git apply --include <skip_if_exists-path-1> [...]
with the second diff on stdin (only if there are anyskip_if_exists
paths)The text was updated successfully, but these errors were encountered: