Closed Peterdes closed 3 years ago
Thanks so much for this, this is definitely a bug/oversight in chezmoi.
but this doesn't pass some tests which is not cery surprising, but I don't understand what these tests are meant to check.
The tests check chezmoi's lazy execution of templates. chezmoi should only loads, parse, and execute templates if their contents are needed, for both performance and usability reasons. The usability aspect is that some templates might call password manager template functions, which might require user interaction to be evaluated, and you only want to trigger this user interaction if it is absolutely needed.
In the specific tests that fail here chezmoi uses invalid templates that trigger an error if they are executed as a trap to ensure that the templates are not even parsed. For example, the chezmoi managed
command should only deal with filenames, and should never parse or execute any templates.
Your fix is really close to correct and revealed a subtle bug in chezmoi where templates were loaded (but not parsed) when they didn't need to be. #1496 completes the fix, but I would like to ensure that you get credit for your thorough investigation and work here. I couldn't find a recent email address in your GitHub profile. Could you please send me an email (address on my GitHub profile) so I can update the commits in #1496 to include credit to you?
Thanks for tackling that so quickly! I'm glad I could help.
Took a look at the fix, good job. I did consider copying the lazycontents stuff from newFileTargetStateEntryFunc but I didn't know what to do in other cases to stay in the lazy parsing scenario (lazyContents = newLazyContents(contents)
). Anyway, I added my email to my profile, thanks for the credit :)
Fixed with @Peterdes in #1496.
Problem: no file starting with create_ is being processed as a template. Example: create a file named "create_dumb.tmpl" with contents
then run
chezmoi apply -nv
. The template is not processed.It is because
newCreateTargetStateEntryFunc
ininternal/chezmoi/sourcestate.go
does not involve any template processing.The behavior is fixed by the following change:
but this doesn't pass some tests which is not cery surprising, but I don't understand what these tests are meant to check.
Is this behavior intentional? If yes, why? If no, could you fix it?