Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go Modules "unknown revision" error when using commit hash

Tags:

go

I need to pull this commit into my go project.

I've tried multiple versions of go.mod:

...

require (
    github.com/libp2p/[email protected]

    // and...
    github.com/libp2p/go-libp2p-core v0.0.0-20190626-aca080dccfc2c9933df66baafe6cf9cc4f429825
)

...

Both result in errors when running $ go build:

$ go build
go: finding github.com/libp2p/go-libp2p-core v0.0.0-20190626-aca080dccfc2c9933df66baafe6cf9cc4f429825
go: finding github.com/libp2p/go-libp2p-core v0.0.7-0.20190626134135-aca080dccfc2
go: github.com/libp2p/go-libp2p-core@v0.0.0-20190626-aca080dccfc2c9933df66baafe6cf9cc4f429825: unknown revision v0.0.0-20190626-aca080dccfc2c9933df66baafe6cf9cc4f429825
go: github.com/libp2p/[email protected]: unknown revision aca080dccfc2
go: error loading module requirements

Go getting doesn't work, either:

$ go get github.com/libp2p/go-libp2p-core@aca080dccfc2c9933df66baafe6cf9cc4f429825
go: finding github.com/libp2p/go-libp2p-core v0.0.7-0.20190626134135-aca080dccfc2                                                                                                    go: github.com/libp2p/[email protected]: unknown revision aca080dccfc2
go: error loading module requirements

As @JimB points out, that hash wasn't merged and was rebased. So I tried to replace it with a new one, but it's still trying to fetch the old one?

$ go get github.com/libp2p/[email protected]
go: finding github.com/libp2p/go-libp2p-core v0.0.7-0.20190626134135-aca080dccfc2
go: github.com/libp2p/[email protected]: unknown revision aca080dccfc2
go: error loading module requirements
like image 674
Adam Avatar asked Jan 25 '23 23:01

Adam


1 Answers

For your most recent hash aca080dccfc2, was that merged to master, or what does that hash correspond to? From quick look, aca080dccfc2 does not appear to be on master, but I'm not sure what your expectations are regarding that commit.

There are restrictions on what hashes are allowed with modules, for example from this slightly older comment in #27043:

It is present in Git if you look at refs/pulls/nnnnn or whatever the ref is, but not in the main branches and tags. Recent changes cut the search down to main branches and tags, which is more appropriate.

Trying to get that aca080dccfc2 hash does not work for me:

$ go get github.com/libp2p/go-libp2p-core@436d707f7cd0
go: finding github.com/libp2p/go-libp2p-core 436d707f7cd0
go get github.com/libp2p/go-libp2p-core@436d707f7cd0: 
 github.com/libp2p/go-libp2p-core@436d707f7cd0: invalid version: unknown revision 436d707f7cd0

On the other hand, the most recent commit on master does work for me:

$ go get github.com/libp2p/go-libp2p-core@d204016fc64589d0

(Side note: notice I was just using the commit hash by itself after the @. That can be handy in case there is something wrong with a pseudo-version).

You mentioned:

it's still trying to fetch the old one?

I'm not sure if that is your primary issue, but in general if you are not sure where a version is coming from, a good place to start is often:

go mod graph | grep <module-of-interest>

or in your case:

go mod graph | grep go-libp2p-core

From the documentation:

'go mod graph' prints the module requirement graph (with replacements applied) in text form. Each line in the output has two space-separated fields: a module and one of its requirements. Each module is identified as a string of the form path@version, except for the main module, which has no @version suffix.

There are some more general troubleshooting tips for tracking down why a particular version is being used in this FAQ on the modules wiki:

FAQ: What can I check if I am not seeing the expected version of a dependency?

That said, it might be more interesting to first understand what commit you are expecting to work...

like image 172
thepudds Avatar answered Jan 30 '23 00:01

thepudds