Bit confused with Godeps in general. Say I'm contributing Go code to a central repository, and now I need to pull the code and contribute my own code changes. What would be the correct godep flow?
Would it be:
git pull // pull latest master
godep restore // Install the package versions specified in Godeps/Godeps.json to $GOPATH
go get foo/bar // Get package foo/bar and edit your code to import foo/bar
godep save ./... // Saves dependencies
// Then, check into source control
One option:
git pull
godep restore
go get -u foo/bar // -u updates
go test ./...
go run main.go
godep save ./...
But, I don't like restoring to my GOPATH in disconnected HEAD states of git, since I contribute to several other repos (and have gotten errors in the past with this) directly within my GOPATH.
So I usually do this:
git pull
go get -u foo/bar
godep update foo/bar
godep go test ./...
godep go run main.go
Using godep as a prefix changes the $GOPATH for go-related functions.
TIP: set all the flags of your main executable with sensible defaults, for all developers. That way they don't need to pass custom parameters just for local development.
Related
Im pretty new to Go but not to software. Im working on a new team with lots of projects and dependencies so we must use godep.
All the code is structure in the standard Go way, with files in $GOPATH/.../github.com/... etc (including our work which is in github)
I made changes to project A (github.com/ourTeam/A) and I want to run project B (github.com/ourTeam/B) which references A to test my code.
so I commit my work from A in my own branch in A, (and even pushed the branch).
-> All I want is to update B with my new version of A.
From B, I tried:
godep update github.com/A/subpackage. It said 'godep: no packages can be updated'
godep save. It deleted EVERYTHING in the vendor folder, leaving the Godeps.json file empty from any dependencies
manually updating Godeps.json with my commit, then running godep update.
No message but it didnt update anything. Godep save after this change deleted everything too in the vendor folder and Godep.json
What am I missing ?
Note: Im using godep v65 (darwin/amd64/go1.6.2) and godep save -v said
godep: Finding dependencies for [.]
godep: Found package: github.com/ourTeam/B
godep: Deps:
(nothing so the diff with old file removes everything)
The error message when you tried to update tells me that the dependency on A had not been godep-saved before in B. That would mean you need to save it, instead of updating.
Today, I was having the same problem as you using godep save. All dependencies were being removed. However, this got me through it:
$ go get -u github.com/tools/godep # Make sure you have the latest godep (currently v71)
$ godep save ./... # Literally, "./..." is the argument
# The above command may fail with "Package not found ..."
# Install any package not found with "go get some/package/path"
$ go get some/package/path # if necessary
# Try "godep save ./..." again; repeat "go get" for any "not found" errors.
Once godep save returned without errors, I checked and it had done as expected. It only added the new dependency I had imported in the code.
Hi i am following the link https://github.com/hashicorp/terraform . As per given section "Adding a dependency" i have successfully run below commands
git checkout master
git pull
godep restore -v # flag is optional, enables verbose output
git checkout my-feature-branch
git rebase master
Now when i run
godep save ./...
i am getting few packages not found.
if i manually update this package with go get then it looks another one and so on..
Please let me know how can i run this successfully thanks
godeps requires the dependencies to be already in your GOPATH. If you haven't downloaded the dependencies (yet), first run
go get ./...
Then you can run
godep save ./...
I started using godep a while ago but I think I'm failing to understand the principal, and I may be using it incorrectly entirely.
I thought godep maintains _workspace in order to have a local copy of the packages in case some revisions/projects are removed or become unavailable. But godep restore doesn't seem to use _workspace at all.
Also, calling godep save for the second time didn't update _workspace, only Godeps.json.
What am I missing?
UPDATE:
To explain my question I changed one of the revisions in my Godeps.json to an invalid revision "1" and ran godep restore. Here's the error I got:
$GOPATH/bin/godep restore
# cd /home/iliga/gopath/src/github.com/jinzhu/gorm; git pull --ff-only
From https://github.com/jinzhu/gorm
a97a508..087b708 master -> origin/master
You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details.
git pull <remote> <branch>
# cd /home/iliga/gopath/src/github.com/jinzhu/gorm; git checkout 1
error: pathspec '1' did not match any file(s) known to git.
godep: restore: exit status 1
As explained above, I would expect there to be no error and for godep to simply copy the code from _workspace.
"godep restore" does not use _workspace. It reads Godeps.json and check out your dependencies to GOPATH.
To use _workspace, you run go command prefixed with godep, like "godep go build", "godep go test".
I have followed the instructions # https://github.com/tools/godep regarding updating a dependency but when I go to build\install using the altered version it has not been updated within Godeps/_workspace/pkg
So I have
go get github.com/golang/glog
godep save
godep go install
and I can see
The modification timestamp in Godeps/_workspace/pkg/linux_amd64/github.com/golang/glog.a
The rev commit value in Godeps/Godeps.json
but now when I want to update I follow the instructions
go get github.com/golang/glog
godep update github.com/golang/glog
godep go install
I observe the following
The Godeps/Godeps.json rev commit has been updated
Godeps/_workspace/src/github.com/golang/ source is updated
But the file timestamp for odeps/_workspace/pkg/linux_amd64/github.com/golang/glog.a is not updated hence we are using the previous version
I believe I should add a .gitignore entry for pkg and bin, which means we would do a clean build on a fresh git clone
I know I could do a rm -r on both the pkg and bin directories before the godep go install command
Is this expected behavior ?
Thanks in advance
Pat
FYI
Since golang v1.4 I can now use the -a flag for the go install command, since it now longer tries to rebuild the standard library, see the v1.4 release notes section on the change to the build -a flag
Obviously this does not apply in pre v1.4 as it will attempt to rebuild the standard library packages
When deploying a Go project to Heroku, installation of the pq package fails. I've posted this in heroku buildpack github issues as well.
Error at deploy time:
-----> Running: godep go install -tags heroku ./...
gournay.go:10:3: cannot find package "github.com/lib/pq" in any of:
/app/tmp/cache/go1.2.1/go/src/pkg/github.com/lib/pq (from $GOROOT)
/tmp/build_ce268203-801e-4dfc-a56c-d70698d6c5bf/.heroku/g/src/github.com/andyatkinson/gournay/Godeps/_workspace/src/github.com/lib/pq (from $GOPATH)
/tmp/build_ce268203-801e-4dfc-a56c-d70698d6c5bf/.heroku/g/src/github.com/lib/pq
godep: go exit status 1
go get and go install run locally as expected. The project is built and running locally. I believe my package structure is correct, and GOPATH and GOROOT are correct. I am using godep which creates the dependencies file below. The source for the pq package appears to be copied into the project, so it seems like it would compile from that source.
~/go/src/github.com/andyatkinson/gournay (master) $ cat Godeps/Godeps.json
{
"ImportPath": "github.com/andyatkinson/gournay",
"GoVersion": "go1.2.1",
"Deps": [
{
"ImportPath": "github.com/lib/pq",
"Rev": "c808a1bb644594ca717ac61f71e6b0e454b835e2"
}
]
}
Am I missing something? Anything else I should check? Thanks!
Do you run godep save on development?
from godep README:
$ godep save
This will save a list of dependencies to the file Godeps/Godeps.json,
and copy their source code into Godeps/_workspace. Read over its
contents and make sure it looks reasonable.
Then commit the file to version control.
--- UPDATE ---
I see your repo, and up on heroku http://warm-depths-3154.herokuapp.com/, follow the steps
rm -Rf gopack.config .godir .gopack
godep save
git add --all . // please commit the Godep folder
git commit -m 'using godep, removed gopack'
(the commit https://github.com/dukex/gournay/commit/0de2390835357879a34ea452a56eeeb6391e5ba8)