Closed tpoliaw closed 1 year ago
Thanks for reporting this. I suspect that the bug is in the diff library that chezmoi uses, which I updated to the latest version recently.
Could you try with the old chezmoi 2.29.1 and report if the bug still occurs?
Looks like that version is ok.
Incidentally, I kept trying to find a simpler example and I don't think it's related to templating. Adding the example above normally and then adding an empty line between one and two does the same thing.
Yeah, I don't think this is related to templating in any way. It's the diff library, which has been shaky since version 1.2.0 onward.
Ok, I'll use an external diff tool for now. Thanks for looking at it and for chezmoi in general. Have been very happy with it otherwise.
I faced the same issue and there is indeed a bug in go-diff
. I created this PR https://github.com/sergi/go-diff/pull/136 which should fix it. Hopefully the review won't take too long.
Awesome, thank you @kdarkhan!
I've released chezmoi v2.29.4 which reverts the diff library to a working version.
Describe the bug
Running
chezmoi diff ~/path/to/file
shows a diff that does not apply to the file and/or highlights incorrect lines as being added or deleted.From testing locally I can't see a consistent reason why some files fail yet.
To reproduce
I first came across this in a large i3 config file but the following was able to reproduce an example of it.
Create a file
~/demo
containing ten lines, egone
toten
.Add it to chezmoi
chezmoi add --template ~/demo
In the chezmoi repo directory add
{{ if true }} helloWorld {{ end}}
as the second line to add a line containinghelloWorld
betweenone
andtwo
.Run
chezmoi diff ~/demo
Expected behavior
I would expect the above diff to show
Output of command with the
--verbose
flagNo change, the diff is the same and nothing else is output
Output of
chezmoi doctor
Additional context
It is difficult to pin down an instance that triggers the bug. In the example above for instance, adding the template line to somewhere other than the second line doesn't cause it. Similarly, changing the number of lines seems to stop the bug appearing. The original i3 config file that first showed the bug is a 246 line template generating a 235 line file (for this machine).
Running
chezmoi apply -v
shows the same diff but applies the correct change.