Do not overwrite files when there are no diffs in Overwrite mode
@@ -128,10 +128,13 @@ pub fn write_file<T>(text: &StringBuffer,
}
}
WriteMode::Overwrite => {
- // Write text directly over original file.
+ // Write text directly over original file if there is a diff.
+ let (source, formatted) = source_and_formatted_text(text, filename, config)?;
+ if source != formatted {
let file = File::create(filename)?;
write_system_newlines(file, text, config)?;
}
+ }
WriteMode::Plain => {
write_system_newlines(out, text, config)?;
}
