Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: origin does not appear to be a git repo error on all go mod commands #38709

Closed
balopat opened this issue Apr 27, 2020 · 8 comments
Closed
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Milestone

Comments

@balopat
Copy link

balopat commented Apr 27, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.1 darwin/amd64

Does this issue reproduce with the latest release?

no.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/balintp/Library/Caches/go-build"
GOENV="/Users/balintp/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/balintp/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/balintp/skaffold/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lk/h2pmhk456999cwnrm162297400fv8w/T/go-build176808651=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go list -m -json or any go mod commands

What did you expect to see?

{
        "Path": "github.com/GoogleContainerTools/skaffold",
        "Main": true,
        "Dir": "/Users/balintp/skaffold",
        "GoMod": "/Users/balintp/skaffold/go.mod",
        "GoVersion": "1.14"
}

What did you see instead?

go: github.com/moby/buildkit@v0.7.1 requires
        github.com/docker/distribution@v0.0.0-20200223014041-6b972e50feee requires
        github.com/bugsnag/panicwrap@v0.0.0-20151223152923-e2c28503fcd0: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /Users/balintp/go/pkg/mod/cache/vcs/3930fbb77689992ff1e965e902478ed592c6673062a4ad1276ed7dda23a6a131: exit status 128:
        fatal: 'origin' does not appear to be a git repository
        fatal: Could not read from remote repository.
        
        Please make sure you have the correct access rights

Deleting the cache folder ended up helping:
rm -rf /Users/balintp/go/pkg/mod/cache/vcs/3930fbb77689992ff1e965e902478ed592c6673062a4ad1276ed7dda23a6a131

Which means that somehow the cache gets into an invalid state (not sure how that happened). And I wish I'd moved the folder instead of deletion - now I can't give you more detail around what the state of that folder was.

@bcmills
Copy link
Contributor

bcmills commented Apr 28, 2020

Thanks for the report. Since this appears to be filesystem corruption and we don't know the cause, I'm going to go ahead and close this issue, but we'll watch for a pattern — if we get more reports of similar issues we'll certainly want to take a closer look.

CC @jayconrod @matloob

@bcmills bcmills closed this as completed Apr 28, 2020
@bcmills bcmills changed the title origin does not appear to be a git repo error on all go mod commands cmd/go: origin does not appear to be a git repo error on all go mod commands Apr 28, 2020
@bcmills bcmills added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin labels Apr 28, 2020
@bcmills bcmills added this to the Unplanned milestone Apr 28, 2020
@matthewmueller
Copy link

matthewmueller commented Jul 12, 2020

I'd like to note that this just happened to me as well.

$ go get -u github.com/matthewmueller/diff
go get github.com/matthewmueller/diff: module github.com/matthewmueller/diff: git ls-remote -q origin in /Users/m/Go/pkg/mod/cache/vcs/5f9f95779422363e8e24e203ef2f34dbab3a4cb052f98aa116323dc518593f13: exit status 128:
        fatal: 'origin' does not appear to be a git repository
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.
$ git remote -v
origin  git@github.com:matthewmueller/duojs.git (fetch)
origin  git@github.com:matthewmueller/duojs.git (push)
$ rm -rf /Users/m/Go/pkg/mod/cache/vcs/5f9f95779422363e8e24e203ef2f34dbab3a4cb052f98aa116323dc518593f13
$ go get -u github.com/matthewmueller/diff
go: github.com/matthewmueller/diff upgrade => v0.0.0-20191220174011-88a65b538395
go: github.com/sergi/go-diff upgrade => v1.1.0
go: github.com/kr/pretty upgrade => v0.2.0
go: github.com/kr/text upgrade => v0.2.0
go: downloading github.com/kr/text v0.2.0

I recently made this repository public and added go.mod (not sure if before or after).

@jayconrod
Copy link
Contributor

@matthewmueller Which repository did you make public? github.com/matthewmueller/diff? The public status of the main repository (git@github.com:matthewmueller/duojs.git shouldn't matter here.

Are you able to reproduce this? If so, can you post the config file for the repository with the error? It would have been /Users/m/Go/pkg/mod/cache/vcs/5f9f95779422363e8e24e203ef2f34dbab3a4cb052f98aa116323dc518593f13/config.

Could you post any relevant parts of ~/.gitconfig? I'd be particularly interested in any url and insteadOf lines.

@matthewmueller
Copy link

matthewmueller commented Jul 13, 2020

Which repository did you make public? github.com/matthewmueller/diff?

Yep!

Are you able to reproduce this? If so, can you post the config file for the repository with the error? It would have been /Users/m/Go/pkg/mod/cache/vcs/5f9f95779422363e8e24e203ef2f34dbab3a4cb052f98aa116323dc518593f13/config.

Sorry, I deleted this cache. I'll be sure to save it if I run into this again.

Could you post any relevant parts of ~/.gitconfig? I'd be particularly interested in any url and insteadOf lines.

[url "git@github.com:"]
	insteadOf = https://github.com/

This has been here for awhile though.

One thing I did recently is add GOPRIVATE to my rc file so I can pull from private repositories

export GOPRIVATE=github.com/matthewmueller

@jayconrod
Copy link
Contributor

@matthewmueller Your ~/.gitconfig file explains the remote SSH URLs. And it seems like those URLs should still be valid. I can't think of a reason why anything here would cause problems.

If you (or anyone else) run into this problem in the future, it would be helpful if you could post:

  • Git version.
  • Any changes to repository privacy, remote URLs, authentication that might cause this.
  • Repository config file.
  • Ideally, a .zip of the repository inside the module cache (maybe a lot to ask I know; it would help us rule out file corruption).

@yessypp
Copy link

yessypp commented Mar 24, 2021

@balopat @matthewmueller you are a life-saver! I have been looking for the solution for almost a day, and this is exactly what fix mine. Thank you for sharing!

@jredl-va
Copy link

I wish I had read to the bottom of this issue about saving the cache folder for troubleshooting. I turfed my cache after running into this error:

	github.com/dlclark/regexp2: module github.com/dlclark/regexp2: git ls-remote -q origin in /Users/jesseredl/go/pkg/mod/cache/vcs/41f57ef0dad41000850e307b84f39892ac7069a4e73d6b9c629532f5cbf182af: exit status 128:
	fatal: 'origin' does not appear to be a git repository
	fatal: Could not read from remote repository.

	Please make sure you have the correct access rights
	and the repository exists.

@r-ashish
Copy link

r-ashish commented Apr 29, 2022

We faced this issue recently and for us it was introduced due to the recent git vulnerability update i.e, the pkg mod cache was owned by some other user and go process was being run by another user. Since git prevents you from running git commands inside dirs not owned by you after the recent update (fatal: unsafe repository (‘/dir/path’ is owned by someone else), go was unable to run git ls-remote -q origin and hence the failure.

We also initially thought that the cache got corrupted somehow but that wasn't the case for us. So, for others who face this issue in the future, please try this first before deleting the cache to find the RC:

# cd to the cache dir reported in the error msg, eg.
cd $GOPATH/pkg/mod/cache/vcs/a3...70
git remote -v # should show origin as a remote
# for us all git commands were failing but if the above command works for you then try the actual command being run by go. i.e,
git ls-remote -q origin # refer to your error msg to get the exact command, for us it was this.

Question for maintainers - I'm just curious why the actual git error msg wasn't shown by go and fatal: 'origin' does not appear to be a git repository was shown instead 🤔 . It would've been easier to debug with the actual error msg. By original error msg I mean:

fatal: unsafe repository ('/go/pkg/mod/cache/vcs/a3...70' is owned by someone else)
To add an exception for this directory, call:
	git config --global --add safe.directory /go/pkg/mod/cache/vcs/a3...70

@golang golang locked and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
None yet
Development

No branches or pull requests

8 participants