ezekg / git-hound

Git plugin that prevents sensitive data from being committed.
MIT License
309 stars 27 forks source link

Fix Build Errors & README Cleanup #6

Closed cjbarker closed 7 years ago

cjbarker commented 7 years ago

Fixes compile errors in https://github.com/ezekg/git-hound/issues/4 and https://github.com/ezekg/git-hound/issues/5

Includes update of latest vendor source code for sourcegraph/go-diff

Lastly, updates the README for detail steps on how to setup environment and build.

ezekg commented 7 years ago

Any reason you didn't use glide to update sourcegraph/go-diff? That should handle things like updating the vendor directory and fix the failing build (which installs from the glide.lock).

cjbarker commented 7 years ago

Thanks for response.

Yes, I'm relatively new to Golang, and it wasn't clear to me from README what additional dependencies needed to be accounted for beyond running "go install".

Recommend you call this out in compilation steps in README. It's not clear (to a noob) that you're relying on a different dependency manager via glide vs. godeps or if any need to be addressed at all when building from scratch.

cjbarker commented 7 years ago

I'll close this out and send you separate pull with updated README build steps, assuming I can get it to work.

cjbarker commented 7 years ago

I'm still having same issue even after installing glide and getting glide dependencies and GOPATH cannot find "vendor" package dependencies (looking for them in src dir). Any help is appreciated.

~/repos/git-hound]$ glide update
...runs successfully...

~/repos/git-hound]$ export GOPATH=`pwd`
~/repos/git-hound]$ go build
hound.go:4:2: cannot find package "github.com/dlclark/regexp2" in any of:
    /usr/local/go/src/github.com/dlclark/regexp2 (from $GOROOT)
    /Users/c/repos/git-hound/src/github.com/dlclark/regexp2 (from $GOPATH)
main.go:10:2: cannot find package "github.com/fatih/color" in any of:
    /usr/local/go/src/github.com/fatih/color (from $GOROOT)
    /Users/c/repos/git-hound/src/github.com/fatih/color (from $GOPATH)
hound.go:5:2: cannot find package "gopkg.in/yaml.v2" in any of:
    /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
    /Users/c/repos/git-hound/src/gopkg.in/yaml.v2 (from $GOPATH)
hound.go:8:2: cannot find package "sourcegraph.com/sourcegraph/go-diff/diff" in any of:
    /usr/local/go/src/sourcegraph.com/sourcegraph/go-diff/diff (from $GOROOT)
    /Users/c/repos/git-hound/src/sourcegraph.com/sourcegraph/go-diff/diff (from $GOPATH)
ezekg commented 7 years ago

Hey, no problem! I appreciate the PR either way! You're right that I should update the readme with instructions for installing dependencies with glide, I guess I missed that when migrating from godep awhile back. Try running glide install before go build—and if that doesn't work, could I ask what version of Go you're using?

cjbarker commented 7 years ago

Problem still exists after glide install I am running go version go version go1.6 darwin/amd64 see below for full commands STDOUT.

~/repos/git-hound-parent]$ glide install
[WARN]  The name listed in the config file (github.com/ezekg/git-hound) does not match the current location (.)
[INFO]  Downloading dependencies. Please wait...
[INFO]  --> Found desired version locally github.com/dlclark/regexp2 4009c9dc49dd8906bfd4d479c255470d6a477ce5!
[INFO]  --> Found desired version locally github.com/fatih/color 34e4ee095d12986a2cef5ddb9aeb3b8cfcfea17c!
[INFO]  --> Found desired version locally github.com/gogo/protobuf 9df9efe4c742f1a2bfdedf1c3b6902fc6e814c6b!
[INFO]  --> Found desired version locally github.com/mattn/go-colorable ded68f7a9561c023e790de24279db7ebf473ea80!
[INFO]  --> Found desired version locally github.com/mattn/go-isatty fc9e8d8ef48496124e79ae0df75490096eccf6fe!
[INFO]  --> Found desired version locally golang.org/x/sys a2e06a18b0d52d8cb2010e04b372a1965d8e3439!
[INFO]  --> Found desired version locally gopkg.in/yaml.v2 cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b!
[INFO]  --> Found desired version locally sourcegraph.com/sourcegraph/go-diff 7eefa0faf57871a70d7a2c368a454593f07797bc!
[INFO]  --> Found desired version locally sourcegraph.com/sqs/pbtypes 4d1b9dc7ffc3f7b555de9b02055fa616f0ebcd18!
[INFO]  Setting references.
[INFO]  --> Setting version for github.com/mattn/go-isatty to fc9e8d8ef48496124e79ae0df75490096eccf6fe.
[INFO]  --> Setting version for github.com/fatih/color to 34e4ee095d12986a2cef5ddb9aeb3b8cfcfea17c.
[INFO]  --> Setting version for github.com/dlclark/regexp2 to 4009c9dc49dd8906bfd4d479c255470d6a477ce5.
[INFO]  --> Setting version for github.com/mattn/go-colorable to ded68f7a9561c023e790de24279db7ebf473ea80.
[INFO]  --> Setting version for github.com/gogo/protobuf to 9df9efe4c742f1a2bfdedf1c3b6902fc6e814c6b.
[INFO]  --> Setting version for sourcegraph.com/sqs/pbtypes to 4d1b9dc7ffc3f7b555de9b02055fa616f0ebcd18.
[INFO]  --> Setting version for golang.org/x/sys to a2e06a18b0d52d8cb2010e04b372a1965d8e3439.
[INFO]  --> Setting version for gopkg.in/yaml.v2 to cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b.
[INFO]  --> Setting version for sourcegraph.com/sourcegraph/go-diff to 7eefa0faf57871a70d7a2c368a454593f07797bc.
[INFO]  Exporting resolved dependencies...
[INFO]  --> Exporting github.com/dlclark/regexp2
[INFO]  --> Exporting github.com/fatih/color
[INFO]  --> Exporting github.com/gogo/protobuf
[INFO]  --> Exporting github.com/mattn/go-colorable
[INFO]  --> Exporting github.com/mattn/go-isatty
[INFO]  --> Exporting golang.org/x/sys
[INFO]  --> Exporting gopkg.in/yaml.v2
[INFO]  --> Exporting sourcegraph.com/sourcegraph/go-diff
[INFO]  --> Exporting sourcegraph.com/sqs/pbtypes
[INFO]  Replacing existing vendor dependencies
~/repos/git-hound-parent]$ go build
hound.go:4:2: cannot find package "github.com/dlclark/regexp2" in any of:
    /usr/local/go/src/github.com/dlclark/regexp2 (from $GOROOT)
    /Users/c/repos/git-hound-parent/src/github.com/dlclark/regexp2 (from $GOPATH)
main.go:10:2: cannot find package "github.com/fatih/color" in any of:
    /usr/local/go/src/github.com/fatih/color (from $GOROOT)
    /Users/c/repos/git-hound-parent/src/github.com/fatih/color (from $GOPATH)
hound.go:5:2: cannot find package "gopkg.in/yaml.v2" in any of:
    /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
    /Users/c/repos/git-hound-parent/src/gopkg.in/yaml.v2 (from $GOPATH)
hound.go:8:2: cannot find package "sourcegraph.com/sourcegraph/go-diff/diff" in any of:
    /usr/local/go/src/sourcegraph.com/sourcegraph/go-diff/diff (from $GOROOT)
    /Users/c/repos/git-hound-parent/src/sourcegraph.com/sourcegraph/go-diff/diff (from $GOPATH)
~/repos/git-hound-parent]$ go version
go version go1.6 darwin/amd64
ezekg commented 7 years ago

Okay, so I think this is because the project is not in your Go path. Go is pretty picky about the fact that your GOPATH should never change—so I believe the problem is that you're modifying your Go path to pwd. What you should do is go install github.com/ezekg/git-hound and then try and build the code installed within your Go path e.g. $GOPATH/src/github.com/ezekg/git-hound.

You should be able to update the version within the glide.yaml for the sourcegraph/go-diff dependency and then run glide update to grab the new version. I just tested this and the build works when inside of the Go path, but crashes like above when outside (because I guess Go is expecting a certain directory structure for the project's parent folders).

cjbarker commented 7 years ago

Argh, yes, $GOPATH was issue. I still haven't quite figured out why everything needs to fall under one central path for GO src vs. telling it a relative or absolute directory where it can find source and dependencies. Thanks for the help.

ezekg commented 7 years ago

No problem, glad you got it figured out! Feel free to make another PR if you do want to update sourcegraph/go-diff to the latest version. 👍