Skip to content

Commit

Permalink
yamlfmt: don't write diff if not changed
Browse files Browse the repository at this point in the history
This PR changes file diff application to not write the file if it wasn't
changed.
  • Loading branch information
braydonk committed Mar 8, 2024
1 parent 4ae531d commit b285396
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (fd *FileDiff) StrOutputQuiet() string {
}

func (fd *FileDiff) Apply() error {
// If there is no diff in the format, there is no need to write the file.
if !fd.Diff.Changed() {
return nil
}
return os.WriteFile(fd.Path, []byte(fd.Diff.Formatted), 0644)
}

Expand Down

0 comments on commit b285396

Please sign in to comment.