Skip to content

Commit 8457a27

Browse files
committed
hclfmt: avoid rewrites when there are no changes in a file
this is faster for large trees and also helps to make tools like [treefmt](https://github.com/numtide/treefmt) to work.
1 parent 27df1ec commit 8457a27

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cmd/hclfmt/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func processFiles() error {
106106

107107
func processFile(fn string, in *os.File) error {
108108
var err error
109+
var hasLocalChanges bool = false
109110
if in == nil {
110111
in, err = os.Open(fn)
111112
if err != nil {
@@ -131,9 +132,10 @@ func processFile(fn string, in *os.File) error {
131132

132133
if !bytes.Equal(inSrc, outSrc) {
133134
changed = append(changed, fn)
135+
hasLocalChanges = true
134136
}
135137

136-
if *overwrite {
138+
if hashLocalChanges && *overwrite {
137139
return ioutil.WriteFile(fn, outSrc, 0644)
138140
}
139141

0 commit comments

Comments
 (0)