Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wking
Copy link
Contributor

@wking wking commented Jan 22, 2018

This makes fixing errors easier. Before this commit, errors looked like:

$ make gofmt
!!! 'gofmt -s' needs to be run on the following files:
./lib/config.go
make: *** [gofmt] Error 1

But that's not very helpful when your local gofmt thinks the file is fine. With this commit, errors will look like:

$ make gofmt
diff --git a/lib/config.go b/lib/config.go
index 1acca8c7..6a63b2b0 100644
--- a/lib/config.go
+++ b/lib/config.go
@@ -2,7 +2,7 @@ package lib

 import (
         "bytes"
-"io/ioutil"
+       "io/ioutil"

        "github.com/BurntSushi/toml"
        "github.com/kubernetes-incubator/cri-o/oci"
make: *** [Makefile:67: gofmt] Error 1

(or whatever, I just stuffed in a formatting error for demonstration purposes).

@wking wking requested review from mrunalp and runcom as code owners January 22, 2018 23:52
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 22, 2018
@openshift-ci-robot
Copy link

Hi @wking. Thanks for your PR.

I'm waiting for a openshift or kubernetes-incubator member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 22, 2018
@wking wking force-pushed the gofmt-show-diff branch 3 times, most recently from 92a8a30 to 53cf0c3 Compare January 23, 2018 00:44
@wking wking changed the title verify-gofmt: Use 'git diff' to show what needs to be changed Makefile: Use 'git diff' to show gofmt changes Jan 23, 2018
@wking
Copy link
Contributor Author

wking commented Jan 23, 2018

I've pushed 99af05a8dbc2d1, dropping verify-gofmt.sh in favor of two Makefile lines. Now that Git is handling difference display and exit codes, the check is simple enough to not need a helper script.

This makes fixing errors easier.  Before this commit, errors looked
like [1]:

  $ make gofmt
  !!! 'gofmt -s' needs to be run on the following files:
  ./lib/config.go
  make: *** [gofmt] Error 1

But that's not very helpful when your local gofmt thinks the file is
fine.  With this commit, errors will look like:

  $ make gofmt
  find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
  git diff --exit-code
  diff --git a/lib/config.go b/lib/config.go
  index 1acca8c7..6a63b2b 100644
  --- a/lib/config.go
  +++ b/lib/config.go
  @@ -2,7 +2,7 @@ package lib

   import (
          "bytes"
  -"io/ioutil"
  +       "io/ioutil"

          "github.com/BurntSushi/toml"
          "github.com/kubernetes-incubator/cri-o/oci"
  make: *** [Makefile:68: gofmt] Error 1

(or whatever, I just stuffed in a formatting error for demonstration
purposes).

Also remove the helper script in favor of direct Makefile calls,
because with Git handling difference reporting and exit status, this
becomes a simpler check.  find's -exec, !, and -path arguments are
specified in POSIX [2].

[1]: https://travis-ci.org/kubernetes-incubator/cri-o/jobs/331949394#L1075
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

Signed-off-by: W. Trevor King <[email protected]>

gofmt:
@./hack/verify-gofmt.sh
find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this actually running gofmt on the code? If so, it won't display any issues in the code in a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this actually running gofmt on the code?

Yes.

If so, it won't display any issues in the code in a PR.

Right. But the next line's git diff ... will show them (and return non-zero) if anything changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't quite work for me locally:

[mrunalp@localhost cri-o]$ git diff
diff --git a/server/container_create.go b/server/container_create.go
index 506bcf79..492d8eea 100644
--- a/server/container_create.go
+++ b/server/container_create.go
@@ -295,7 +295,7 @@ func addDevices(sb *sandbox.Sandbox, containerConfig *pb.ContainerConfig, specge
                                UID:   &hostDevice.Uid,
                                GID:   &hostDevice.Gid,
                        }
-                       if hostDevice.Major == 0 && hostDevice.Minor == 0 {
+                               if hostDevice.Major == 0 && hostDevice.Minor == 0 {
                                // Invalid device, most likely a symbolic link, skip it.
                                continue
                        }
[mrunalp@localhost cri-o]$ make gofmt
find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
git diff --exit-code
[mrunalp@localhost cri-o]$ echo $?
0
[mrunalp@localhost cri-o]$ git diff
[mrunalp@localhost cri-o]$

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, I see the point. It would have shown the bad changes if present in the bad commit.

Copy link
Member

@mrunalp mrunalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mrunalp
Copy link
Member

mrunalp commented Jan 23, 2018

@rhatdan @runcom PTAL

@TomSweeneyRedHat
Copy link
Contributor

LGTM, neat little change!

@rhatdan
Copy link
Contributor

rhatdan commented Jan 24, 2018

LGTM
/test all

@openshift-ci-robot
Copy link

@wking: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/e2e_fedora 8dbc2d1 link /test e2e_fedora

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@runcom
Copy link
Member

runcom commented Jan 24, 2018

this doesn't need e2e 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants