gitutil: silence git advice hints during checkout - #6972
Open
youdie006 wants to merge 1 commit into
Open
Conversation
An ADD from a git context runs 'git checkout FETCH_HEAD', which prints detached-HEAD advice into the build output. Set GIT_ADVICE=0 by default in GitCLI.Run (covers all advice on Git >= 2.45) and pass -c advice.detachedHead=false as a fallback for older Git. An operator can restore the hints for debugging by setting GIT_ADVICE explicitly in buildkitd's environment, in which case it is forwarded as-is. Signed-off-by is included. Closes moby#6963. Signed-off-by: youdie006 <youdie006@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An
ADDfrom a git context runsgit checkout FETCH_HEAD, which prints Git's detached-HEAD advice into the build output (#6963). This silences that advice noise.Changes
All git invocations flow through
GitCLI.Runinutil/gitutil/git_cli.go(it already centralizes global git settings such as-c protocol.file.allow=user), so the fix lands in that one place:GIT_ADVICE=0in the command environment by default — disables all advice hints on Git >= 2.45 (your stated preference in the issue).-c advice.detachedHead=falseas a fallback for older Git releases that predateGIT_ADVICE, keeping the specific detached-HEAD checkout noise quiet there too.GIT_ADVICEexplicitly in buildkitd's environment (e.g.GIT_ADVICE=1), it is forwarded as-is and theadvice.detachedHead=falseoverride is dropped, so full advice output returns.I deliberately kept this to the two levers you endorsed rather than implementing the broader curated advice-policy table from the issue discussion, to keep the change minimal and avoid a policy decision — happy to extend it if you'd prefer the curated approach.
Tests
Added
TestGitCLIAdvice(using the package's existingWithExeccommand-capture pattern): it assertsGIT_ADVICE=0and theadvice.detachedHead=falsearg are present by default, and that they are restored/dropped whenGIT_ADVICEis set for debugging.go build,go vet, andgo test ./util/gitutil/...all pass.Closes #6963.
AI disclosure: this PR was drafted with Claude Code (AI-assisted). Verified with go build / vet / test on the changed package (all pass). DCO sign-off included.