This article is now published on my website: Prefer Subshells for Context.
WARNING: If you're reading this in 2021 or later, you're likely better served by reading:
- https://go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code
- https://go.dev/ref/mod#private-modules
(This gist was created in 2013 and targeted the legacy GOPATH mode.)
$ ssh -A vm
$ git config --global url."[email protected]:".insteadOf "https://github.com/"In Travis CI, I want to check that my Go files are formatted properly via gofmt and goimports. During my CI builds, I only care about formatting issues in my own code, not in third-party repos.
Unfortunately, running a simple gofmt -l . in the root of my project does not work because I'm using Godep, which checks in all of my external dependencies at ./Godep/_workspace. While running go fmt ./... ignores underscore-prefixed subdirectories, the plain gofmt . does not. Neither gofmt nor goimports take the ./... arg:
➜ goimports -l ./...
stat ./...: no such file or directorySince I can use go list ./... to get a list of all subpackages in my project (exluding vendored imports in an underscore-prefixed directory), I'm using the following to run gofmt and goimports on each of my own Go files (including _test.go files):
| #traverse all the directory and subdirectory | |
| define walk | |
| $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e))) | |
| endef | |
| #find all the file recursively under jni/ | |
| ALLFILES = $(call walk, $(LOCAL_PATH)) | |
| FILE_LIST := $(filter %.cpp, $(ALLFILES)) | |
| LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) |