rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Only re-write file when contents has actually changed #12

Closed sjoerdjob closed 3 years ago

sjoerdjob commented 3 years ago

When one runs djhtml -i, the "create timestamp" of the file is changed even when the contents is not.

% ls -hal tst*
...    78B May 17 15:19 tst.html
...    38B May 17 15:19 tst.py
% shasum tst*
0c2f9c91c8d22ad4f60aff6c155400a695cf0323  tst.html
291ee7e335a86d6e29f6e0abc0f4d85eef252287  tst.py 
% djhtml -i tst.html
Successfully reformatted tst.html
% black tst.py
All done! ✨ 🍰 ✨
1 file left unchanged.
% shasum tst*
0c2f9c91c8d22ad4f60aff6c155400a695cf0323  tst.html
291ee7e335a86d6e29f6e0abc0f4d85eef252287  tst.py
% ls -hal tst*
...    78B May 17 15:20 tst.html
...    38B May 17 15:19 tst.py

As you can see, black keeps the file unchanged (and thus: the old timestamp), while djhtml writes a new file (and thus: a new timestamp).

Ideally djhtml would report which files are and are not changed, and in particular: not write a new file when it would have the same contents.

JaapJoris commented 3 years ago

Thank you for another great suggestion! I've assigned myself to this issue and will publish an update shortly!