Godep restore doesn't use the code saved in _workspace - go

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

Related

"npm notice created a lockfile as package-lock.json.You should commit this file."

I am getting this instruction on the terminal "npm notice created a lockfile as package-lock.json. You should commit this file." after I tried solving the EAUDITNOLOCK error.
Please help me with an step by step resolution.
Thanks!
To tell git to track the file you would use git add package-lock.json
To then commit it to git commit -m "Adding package lock"
As with any npm based project in git you will want to make sure your .gitingore file contains at the very minimum the following
# Don't commit npm node_module directory
node_modules
If you don't have a .gitignore file, then you will want to create one. For more information on gitignore please see the docs
The pacakge-lock.json itself has benefit described in the npm documentation while boils down to specifically locking your dependencies to exact versions given that your pacakge.json can define version ranges. This helps with debugging and keeping things stable overtime. Committing this file mean that you can always go to previous commit and have your environment setup exactly as it was and others can have your identical environment when they checkout your git repo.

Why does Go-get ask me to pick a branch?

I want to install mongoDB-driver. When I type this command
go get go.mongodb.org/mongo-driver/mongo
I got :
# cd /Users/jiangwei/go/src/go.mongodb.org/mongo-driver; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
package go.mongodb.org/mongo-driver/mongo: exit status 1
Probably because you've already checked out that repo into your Go path, and have changed to a non-default branch. The simplest way to correct it would be to remove that repo, and start from scratch.
rm -rf $(go env GOPATH)/src/go.mongodb.org/mongo-driver
Of course, this will lose any changes you've made in that repo.

Godep save deletes all deps in vendor and godep update

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.

how to update the vendor folder for https://github.com/hashicorp/terraform.git for terraform

Hi i am following steps given for hashicorp/terraform and performed below activity
# Get latest master branch's dependencies staged in local $GOPATH
git checkout master
git pull
godep restore -v
# Make your way to the dependency in question and checkout the target ref
pushd $GOPATH/src/github.com/some/dependency
git checkout [latest]
# Head back to Terraform on a feature branch and update the dependncy to the
# version currently in your $GOPATH
popd
git checkout my-feature-branch
godep update github.com/...
after this i can see my Godep.json file has been updated however i dont see changes in the vendor folder . it still points to old. Well i am looking emr support from vendor for that i am updating go-aws-sdk which is available with the latest go-aws-sdk. when i called go update github.com/... it has modified the godep.json but not vendor folder .
Could somebody please let me know the reason. Thanks
You have to do a godep restore -v again. update only updates the dependency in the Godep.json file.

godep save ./... seems not working for https://github.com/hashicorp/terraform

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

Resources