Skip to content

Commit 42e9a94

Browse files
committed
Don't overwrite file if no changes were made
Always writing to the file, even if unchanged, updates the modified time and prevents incremental builds in Xcode.
1 parent e6b8c60 commit 42e9a94

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)