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: go build fails to read vcs info from isolated git submodule #53640

Closed
MichaelVoelkel opened this issue Jul 1, 2022 · 6 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@MichaelVoelkel
Copy link

MichaelVoelkel commented Jul 1, 2022

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

1.18.3

Does this issue reproduce with the latest release?

Yes, with latest 1.18 (that is, 1.18.3), which is not the latest Go release itself, though

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

It's a docker container but reproduces on Apple Silicon and on Debian 10 x86.

What did you do?

I just tried building my image:

docker build --no-cache -f deploy/Dockerfile .

and got output:

 > [3/4] RUN go build .:
#7 0.265 error obtaining VCS status: exit status 128
#7 0.265 	Use -buildvcs=false to disable VCS stamping.
------
executor failed running [/bin/sh -c go build .]: exit code: 1

What did you expect to see?

No error.

What did you see instead?

Failure.

So, to make this reproducible, I created a nested git repository because the error does not occur if I remove the nested/.git file. Recursively cloning the repo, cding into nested and then run aforementioned build command reproduces it for me on two systems:

https://github.com/MichaelVoelkel/vcs-test

I mean, sure, .git links to a folder that does not exist and just not copying everything into Docker would immediately help. But why does Go even care?

@seankhliao seankhliao changed the title Docker 1.18.3: VCS error in Git submodules cmd/go: go build fails to read vcs info from isolated git submodule Jul 1, 2022
@MichaelVoelkel
Copy link
Author

I mean, if you phrase the title like this...

It cannot read it from there because the submodule that is checked out has, instead of .git folder, a .git file. This file only has the content like:

gitdir=../modules/something

So, clearly it cannot read it.

So the better question is: Why is it needed that VCS is read? And if it's needed, then I am probably the wrongdoer myself for having the isolated submodule?

@seankhliao
Copy link
Member

 > [4/6] RUN git status:
#8 0.832 fatal: not a git repository: /../.git/modules/nested

I would consider this a git issue (the way it handles git dirs in submodules).
Like #53532 we could return a better error (the git output), but ultimately it would still be up to the user to decide if they want to embed vcs info (provide a complete .git dir) or not (-buildvcs=false or remove the .git file/dir).

cc @bcmills @matloob

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Jul 1, 2022
@seankhliao
Copy link
Member

Why is it needed that VCS is read?

I would refer you to the description of the build flag https://pkg.go.dev/cmd/go#:~:text=buildmode%27%20for%20more.-,%2Dbuildvcs,-Whether%20to%20stamp

@bcmills
Copy link
Contributor

bcmills commented Jul 1, 2022

If this is the standard layout for a Git submodule, then perhaps we should change vcs.RepoRootForImportPath to detect that configuration and report the root of the parent repo instead of the submodule directory.

@bcmills bcmills added this to the Backlog milestone Jul 1, 2022
@kkHAIKE
Copy link
Contributor

kkHAIKE commented Jul 30, 2022

we can ignore(goto omitVCS when cfg.BuildBuildvcs is auto) vcsCmd.Status err when .git is file(submodule)

cached := vcsStatusCache.Do(repoDir, func() any {
st, err := vcsCmd.Status(vcsCmd, repoDir)
return vcsStatusError{st, err}
}).(vcsStatusError)
if err := cached.Err; err != nil {
setVCSError(err)
return
}

@gopherbot
Copy link

Change https://go.dev/cl/443597 mentions this issue: cmd/go/internal/vcs: avoid treating git submodule directory as repository root

@dmitshur dmitshur modified the milestones: Backlog, Go1.20 Nov 2, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 2, 2022
romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
Currently, FromDir identifies a VCS checkout directory just by checking
whether it contains a specified file. This is not enough. For example,
although there is a ".git" file (a plain file, not a directory) in a
git submodule directory, this directory is not a git repository root.

This change takes the file mode into account. As of now, the filename
and file mode for the supported VCS tools are:

- Mercurial:    .hg             directory
- Git:          .git            directory
- Bazaar:       .bzr            directory
- Subversion:   .svn            directory
- Fossil:       .fslckout       plain file
- Fossil:       _FOSSIL_        plain file

This CL effectively reverts CL 30948 for golang#10322.

Fixes golang#53640.

Change-Id: Iea316c7e983232903bddb7e7f6dbaa55e8498685
GitHub-Last-Rev: 7a2d6ff
GitHub-Pull-Request: golang#56296
Reviewed-on: https://go-review.googlesource.com/c/go/+/443597
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
socketbox added a commit to pbs/gorson that referenced this issue Dec 13, 2022
socketbox added a commit to pbs/gorson that referenced this issue Dec 13, 2022
easybe added a commit to husqvarnagroup/sshportal that referenced this issue Oct 7, 2023
This in order to fix the following bug:

golang/go#53640
easybe added a commit to husqvarnagroup/sshportal that referenced this issue Oct 21, 2023
This in order to fix the following bug:

golang/go#53640
@golang golang locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants