gml-format: Skip writing formatted GML to file if no changes were made

This stops all GML files from appeared under the "Changes not staged
for commit" section of the commit message comment due to the changed
last-modified timestamp of the file.
This commit is contained in:
Idan Horowitz 2022-02-12 19:28:22 +02:00
parent 0a93bf5e7b
commit 9839a1699f
Notes: sideshowbarker 2024-07-17 18:57:00 +09:00

View File

@ -30,6 +30,8 @@ ErrorOr<bool> format_file(StringView path, bool inplace)
}
auto formatted_gml = formatted_gml_or_error.release_value();
if (inplace && !read_from_stdin) {
if (formatted_gml == contents)
return true;
if (!file->seek(0) || !file->truncate(0)) {
warnln("Could not truncate {}: {}", path, file->error_string());
return false;