Skip to content

Instantly share code, notes, and snippets.

@tt
Created February 10, 2016 19:40
Show Gist options
  • Save tt/a0f6d443cff69161213f to your computer and use it in GitHub Desktop.
Save tt/a0f6d443cff69161213f to your computer and use it in GitHub Desktop.
Godep problem

When installing dependencies, dependencies are evaluated based on the latest version in $GOPATH and not based on whatever version is saved in Godeps/

Steps to reproduce

Install Logrus and reset to old version:

go get github.com/Sirupsen/logrus
(cd $GOPATH/src/github.com/Sirupsen/logrus && git reset --hard 8cdd4b39f502d10358d92586e020d3535f257ec9^)

Create a small program (main.go):

package main

import (
        log "github.com/Sirupsen/logrus"
)

func main() {
        log.Println()
}

Save dependencies:

godep save

This produces the following Godeps/Godeps.json:

{
        "ImportPath": "tmp",
        "GoVersion": "go1.5",
        "Deps": [
                {
                        "ImportPath": "github.com/Sirupsen/logrus",
                        "Comment": "v0.8.7-35-gfe6f2b0",
                        "Rev": "fe6f2b03125e4fcafb21406381010e363a072c80"
                }
        ]
}

Update Logrus on the system (but not for the program):

go get -u github.com/Sirupsen/logrus

Install something that depends on Logrus:

go get github.com/stvp/roll

Alter the program (main.go) to use this library:

package main

import (
        log "github.com/Sirupsen/logrus"
        "github.com/stvp/roll"
)

func main() {
        log.Println()
        roll.New("", "")
}

Save dependencies again:

godep save

One of two things will happen. If the golang.org/x/sys/unix package does not exist in $GOPATH, an error is returned:

godep: Package (golang.org/x/sys/unix) not found

If it does exist, the Godeps/Godeps.json will look like this:

{
        "ImportPath": "tmp",
        "GoVersion": "go1.5",
        "Deps": [
                {
                        "ImportPath": "github.com/Sirupsen/logrus",
                        "Comment": "v0.8.7-35-gfe6f2b0",
                        "Rev": "fe6f2b03125e4fcafb21406381010e363a072c80"
                },
                {
                        "ImportPath": "github.com/stvp/roll",
                        "Rev": "5a526501ee91574c9a06ed5ee5c2be0e22a8171d"
                },
                {
                        "ImportPath": "golang.org/x/sys/unix",
                        "Rev": "eb2c74142fd19a79b3f237334c7384d5167b1b46"
                }
        ]
}

Nothing in Godeps/ has a dependency on that package, though. Only the latest version of Logrus (in $GOPATH) has.

@tt
Copy link
Author

tt commented Mar 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment