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

Open
MichaelVoelkel opened this issue Jul 1, 2022 · 5 comments
Open
Labels
GoCommand help wanted NeedsInvestigation
Milestone

Comments

@MichaelVoelkel
Copy link

@MichaelVoelkel 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

@MichaelVoelkel MichaelVoelkel commented Jul 1, 2022

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

@seankhliao seankhliao commented Jul 1, 2022

 > [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 GoCommand labels Jul 1, 2022
@seankhliao
Copy link
Member

@seankhliao seankhliao commented Jul 1, 2022

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
Member

@bcmills 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 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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand help wanted NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants