Skip to content

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

Description

@thaJeztah

Description

I noticed this in CI runs, and initially thought the output originated from git commands executed within a RUN step, but a closer look shows that it's from git commands executed by BuildKit itself;

docker build -<<'EOF'
FROM alpine
ADD --keep-git-dir=true https://github.com/containers/dnsname.git#v1.3.1 .
EOF
docker buildx history logs
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 124B done
#1 DONE 0.0s

# <cut> ....

#5 [2/2] ADD --keep-git-dir=true https://github.com/containers/dnsname.git#v1.3.1 .
#5 -0.001 512aea91bf1095fbcad0abceec38798df5c40c14	refs/tags/v1.3.1
#5 -0.001 18822f9a4fb35d1349eb256f4cd2bfd372474d84	refs/tags/v1.3.1^{}
#5 0.017 Initialized empty Git repository in /var/lib/desktop-containerd/daemon/io.containerd.snapshotter.v1.overlayfs/snapshots/40167/fs/
#5 1.656 From https://github.com/containers/dnsname
#5 1.656  * [new tag]         v1.3.1     -> v1.3.1
#5 1.658 512aea91bf1095fbcad0abceec38798df5c40c14
#5 1.667 Initialized empty Git repository in /var/lib/desktop-containerd/daemon/io.containerd.snapshotter.v1.overlayfs/snapshots/40168/fs/.git/
#5 1.668 tag
#5 1.723 From file:///var/lib/desktop-containerd/daemon/io.containerd.snapshotter.v1.overlayfs/snapshots/40167/fs
#5 1.723  * [new tag]         v1.3.1     -> v1.3.1
#5 1.758 Note: switching to 'FETCH_HEAD'.
#5 1.758
#5 1.758 You are in 'detached HEAD' state. You can look around, make experimental
#5 1.758 changes and commit them, and you can discard any commits you make in this
#5 1.758 state without impacting any branches by switching back to a branch.
#5 1.758
#5 1.758 If you want to create a new branch to retain commits you create, you may
#5 1.758 do so (now or later) by using -c with the switch command. Example:
#5 1.758
#5 1.758   git switch -c <new-branch-name>
#5 1.758
#5 1.758 Or undo this operation with:
#5 1.758
#5 1.758   git switch -
#5 1.758
#5 1.758 Turn off this advice by setting config variable advice.detachedHead to false
#5 1.758
#5 1.758 HEAD is now at 18822f9 Bump to v1.3.1
#5 DONE 2.5s

#6 [2/2] ADD --keep-git-dir=true https://github.com/containers/dnsname.git#v1.3.1 .
#6 DONE 0.1s

# <cut> ....

We can probably make the output less noisy; from a quick search, git allows setting these configs per invocation, so no need to persist config on disk.

git -c advice.detachedHead=false checkout FETCH_HEAD

or

git -c advice.detachedHead=false switch --detach FETCH_HEAD

There's apparently also a global --no-advice option and corresponding GIT_ADVICE=0 env-var to hide all "advice" output; https://git-scm.com/docs/git#Documentation/git.txt-GITADVICE

GIT_ADVICE

If set to 0, then disable all advice messages. These messages are intended to provide hints to human users that may help them get out of problematic situations or take advantage of new features. Users can disable individual messages using the advice.* config keys. These messages may be disruptive to tools that execute Git processes, so this variable is available to disable the messages. (The --no-advice global option is also available, but old Git versions may fail when this option is not understood. The environment variable will be ignored by Git versions that do not understand it.)

The --no-advice was introduced in Git 2.46.0, which is still relatively recent, so perhaps the GIT_ADVICE=0 would be a safer option to use.

For a list of advices; https://git-scm.com/docs/git-config/2.51.1#Documentation/git-config.txt-advice

Proposal

I think in most cases these messages are just noise, BUT maybe some advices could be useful for debugging, but given that many of these won't be actionable, it may not be useful to most users; as the docs mentions:

intended to provide hints to human users that may help them get out of problematic situations or take advantage of new features

  • -c advice.detachedHead=false should be a safe option to set; I don't think that advice provides much value
  • We can probably set GIT_ADVICE=0 by default; possibly with debug enabled or similar, we could omit it?
  • If we want to apply granular, we should evaluate https://git-scm.com/docs/git-config/2.51.1#Documentation/git-config.txt-advice and create a curated list of advices that are not useful, even for debugging.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions