Godep save deletes all deps in vendor and godep update - godeps

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.

Related

Cannot update dependency package with godeps

I need to update stripe-go library version.
Project has 19.**
New version 52.**
There is a godeps dependency manager
When I try to run
godep save github.com/stripe/stripe-go
I get
godep: cannot save github.com/stripe/stripe-go/form at revision
f8b095462d541c43d981d28de52b7464b25f3ee1: already have
github.com/stripe/stripe-go at revision
87c04229ff0262e4e7dfc8af7dc97a471e955ba2.
Run `godep update github.com/stripe/stripe-go' first.
And when I run
godep update github.com/stripe/stripe-go
I get
godep: no packages can be updated
What do I do wrong?
I remember this issue, quoting from https://github.com/tools/godep/issues/164#issuecomment-101345584
This seems to be caused by this line here:
https://github.com/tools/godep/blob/master/update.go#L205
If packages A and B are under the same root, and I try to only update
B, the root will be marked for skipping update because A isn't being
updated. I'm not sure what the motivation for this feature is, it
seems that developers should be able to selectively update sub
packages as they desire.
For what it's worth, I fixed my problem by globbing from the root in
my godep update command (e.g. godep update github.com/foo/bar/...
instead of github.com/foo/bar/pkg/B. A helpful error message would
have gone a long way
While you're here, go 1.11 and above has inbuilt module support. Maybe look into shifting into that? https://github.com/golang/go/wiki/Modules

Godeps development flow?

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.

How do I get my godep dependencies in my ...project_folder/Godeps/_workspace/?

I was given source code with a Godeps/Godeps.json file. From what I understand is I need to get my dependancies into ...project_folder/Godeps/_workspace/src.
My Go Path:
/users/me/work
I used godep restore which downloaded all the dependancies to /users/me/work/src
Am I supposed to manipulate to the GoPATH so that godep restore puts it where I want? Or do I need to manually copy it after? Or am I just using the wrong command?

Godep restore doesn't use the code saved in _workspace

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".

golang and godep : Build\install after a golang dependency update when using godep?

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

Resources