Skip to content

"gofmt -d" is broken. (and "gofix -diff" too) #1916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gopherbot opened this issue Jun 4, 2011 · 5 comments
Closed

"gofmt -d" is broken. (and "gofix -diff" too) #1916

gopherbot opened this issue Jun 4, 2011 · 5 comments

Comments

@gopherbot
Copy link
Contributor

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.
@rsc
Copy link
Contributor

rsc commented Jun 6, 2011

Comment 1:

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

bradfitz commented Jun 7, 2011

Comment 2:

This issue was closed by revision 687102e.

Status changed to Fixed.

@gopherbot
Copy link
Contributor Author

Comment 3 by fvbommel:

That revision only fixes gofmt, not gofix.

@bradfitz
Copy link
Contributor

bradfitz commented Jun 7, 2011

Comment 4:

Oh, whoops.

@bradfitz
Copy link
Contributor

bradfitz commented Jun 7, 2011

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants