Skip to content

gitutil: silence git advice hints during checkout - #6972

Open
youdie006 wants to merge 1 commit into
moby:masterfrom
youdie006:fix/git-advice-noise
Open

gitutil: silence git advice hints during checkout#6972
youdie006 wants to merge 1 commit into
moby:masterfrom
youdie006:fix/git-advice-noise

Conversation

@youdie006

Copy link
Copy Markdown

What

An ADD from a git context runs git 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.Run in util/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:

  • Set GIT_ADVICE=0 in the command environment by default — disables all advice hints on Git >= 2.45 (your stated preference in the issue).
  • Also pass -c advice.detachedHead=false as a fallback for older Git releases that predate GIT_ADVICE, keeping the specific detached-HEAD checkout noise quiet there too.
  • Debug escape: if an operator sets GIT_ADVICE explicitly in buildkitd's environment (e.g. GIT_ADVICE=1), it is forwarded as-is and the advice.detachedHead=false override 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 existing WithExec command-capture pattern): it asserts GIT_ADVICE=0 and the advice.detachedHead=false arg are present by default, and that they are restored/dropped when GIT_ADVICE is set for debugging. go build, go vet, and go 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make ADD using git context less noisy (GIT_ADVICE=0 or -c advice.detachedHead=false)

1 participant