Closed
Description
by fvbommel:
What steps will reproduce the problem? 1. Create a Go file that's not formatted right. For example: === package main func main() { return } === (Note the lack of indentation before 'return') 2. Run 'gofmt -d' on it. 3. Wonder where your diff output is. Bonus bug: 4) Create a Go file that contains something gofix would change, such as: ===== package main import "http" func foo() (a, b interface{}) { resp, _, err := http.Get(url) return resp, err } ===== 5) Run 'gofix -diff' on it. 6) Experience a deja-vu. What is the expected output? A diff between the on-disk version and the reformatted/fixed version, something like this (for the gofmt example above): ===== diff gofmt-test.go gofmt/gofmt-test.go --- /tmp/gofmt793939221 2011-06-04 17:13:50.000000000 +0200 +++ /tmp/gofmt532065648 2011-06-04 17:13:50.000000000 +0200 @@ -1,5 +1,5 @@ package main func main() { -return + return } ===== What do you see instead? computing diff: exit status 1 Which compiler are you using (5g, 6g, 8g, gccgo)? 6g Which operating system are you using? Ubuntu 10.10 Which revision are you using? (hg identify) 3418f22c39eb weekly/weekly.2011-06-02 The current tip (0f1980acc591 tip) has the same issue. Please provide any additional information below. The diff program returns a non-zero exit status when it finds differences, and the redesigned exec package returns this as a non-nil 'err', which makes gofmt and gofix stop with an error before showing the diff output. The diff() function in gofmt/gofmt.go should return a nil err instead of an *os.Waitmsg indicating that the program exited with non-zero exit status. gofix/main.go includes almost identical code (for gofix -diff), which is equally broken and should be fixed the same way. P.S. I also noticed that 'gofix -diff' doesn't pass '-u' to diff, but 'gofmt -d' does.