Skip to content

Commit f30e81e

Browse files
authored
Merge pull request swiftlang#296 from myyra/prevent-overwriting-unchanged
Don't overwrite files if they are unchanged
2 parents 7acb409 + 32b3571 commit f30e81e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/swift-format/Frontend/FormatFrontend.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ class FormatFrontend: Frontend {
4949
to: &buffer,
5050
parsingDiagnosticHandler: diagnosticsEngine.consumeParserDiagnostic)
5151

52-
let bufferData = buffer.data(using: .utf8)! // Conversion to UTF-8 cannot fail
53-
try bufferData.write(to: url, options: .atomic)
52+
if buffer != source {
53+
let bufferData = buffer.data(using: .utf8)! // Conversion to UTF-8 cannot fail
54+
try bufferData.write(to: url, options: .atomic)
55+
}
5456
} else {
5557
try formatter.format(
5658
source: source,

0 commit comments

Comments
 (0)