diff --git a/src/filemap.rs b/src/filemap.rs index aa3ae8537af..82e8c3e50ae 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -128,9 +128,12 @@ fn create_diff(filename: &str, } } WriteMode::Overwrite => { - // Write text directly over original file. - let file = File::create(filename)?; - write_system_newlines(file, text, config)?; + // 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)?;