S. Yacko
S. Yacko

Reputation: 682

Go get is pulling the wrong repository

My module is gitlab.com/getsote/utilities/slogger My repository is gitlab.com/getsote/utilities/slogger.git When I run go get gitlab.com/getsote/utilities/slogger, I get the message below.

Scotts-Mac-mini:seeding syacko$ go get gitlab.com/getsote/utilities/slogger
go get gitlab.com/getsote/utilities/slogger: module gitlab.com/getsote/utilities/slogger: git ls-remote -q origin in /Users/syacko/workspace/sotesoft/golang/pkg/mod/cache/vcs/80b3644beae1b986f1c659355360479e2463820660aa328d2edb1e571aba259b: exit status 128:
    remote: The project you were looking for could not be found.
    fatal: repository 'https://gitlab.com/getsote/utilities.git/' not found
Scotts-Mac-mini:seeding syacko$ 

The gitlab.com/getsote/utilities.git is a sub-directory and not a repository. I don't understand why go get is going to the utilities as a repository?

==========================

PREVIOUS Updates

Directory Structure:

GOPATH/src/slogger
              |----go.mod
              |----slogger.go
              |----slogger_test.go

go.mod file
module slogger  or  gitlab.com/getsote/utilities/slogger -> still gets the error below

go 1.14

gitlab.com/getsote/utilities contains repository slogger.git

I have run a test to see if the issue is the number of nodes in the path. So, I create a new repository with no sub-directory and pushed the slogger code. Then ran go get gitlab.com/getsote/slogger which generate a different error message.

GOPATH/gitlab.com/getsote/test-go-mod -> create new directory and added slogger files listed above

gitblab.com/getsote/test-go-mod -> new repository with one less level

Scotts-Mac-mini:test-go-mod syacko$ go get gitlab.com/getsote/test-go-mod
go: downloading gitlab.com/getsote/test-go-mod v0.0.0-20200409023538-794310bf7cf9
go get gitlab.com/getsote/test-go-mod: gitlab.com/getsote/[email protected]: verifying module: gitlab.com/getsote/[email protected]: reading https://sum.golang.org/lookup/gitlab.com/getsote/[email protected]: 410 Gone
    server response:
    not found: gitlab.com/getsote/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/7753c92c9bd1419156d8120684b7f3707fd207e01a2947ba89e2acfd2ecfb4d0: exit status 128:
        fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
Scotts-Mac-mini:test-go-mod syacko$ 

This is still getting the status error of 128 for the missing version. Additionally, it is looking in the right location for the code. If this is true, then I just need help with the version missing. Moving to a shorted directory structure is doable.

========================

Newest Update

@praveent > The solution at https://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4 didn't work for me. So I started from scratch to see how to resolve the issue.

Upvotes: 4

Views: 7727

Answers (2)

S. Yacko
S. Yacko

Reputation: 682

So, here is how I got this to work using gitlab.com. I'm not saying other ways will not work, they just didn't for me and my setup. First, since I don't care if the code is available to the public, I created a new group at gitlab.com. This new group is public from the start, so no need to adjust permissions. Then I create a repository called packages and cloned the repository to my local machine with the same directory structure that is in gitlab.com, gitlab.com/soteapps/packages with ~/workspace/soteapps/packages on my machine. Both of these are out side the GOPATH. I'm not sure this matters, but it is working this way, so I'm putting it here.

Under packages, I copied the slogger directory and code.

cp -R slogger ~/workspace/soteapps/packages/.

Edited the go.mod file to match the repository structure, which is in the packages directory. There is no go.mod file in the slogger directory.

module gitlab.com/soteapps/packages

go 1.14

Edited the hello.go import to match the package.

package main

import (
    "fmt"
    "rsc.io/quote"
    "gitlab.com/soteapps/packages/slogger"
)

func main() {
    fmt.Println(quote.Hello())
    slogger.Info("Test message")
}

Built the program using go build -o hello and then ran it hello with the following results:

Scotts-Mac-mini:hello syacko$ hello
Hello, world.
INFO:2020/04/10 21:11:33 Test message
Scotts-Mac-mini:hello syacko$ 

Worked! Thank you all that helped. This wouldn't of gotten solved without your help.

Note: This only works for public repositories.

Upvotes: 0

praveent
praveent

Reputation: 600

The reason is because for a git repository it assumes that utilities is the repo and not utilities/slogger

There is a way to override this behavior by implementing go get API. But, gitlab is yet to implement the same due to security concerns. You can read more here. Gitlab issue

Update: Add reference to gitlab issue tracking this problem.

Upvotes: 1

Related Questions