Skip to content

gitutil: avoid global git config lookup on Windows#6639

Merged
crazy-max merged 1 commit intomoby:masterfrom
tonistiigi:git-windows-conf-fix
Apr 2, 2026
Merged

gitutil: avoid global git config lookup on Windows#6639
crazy-max merged 1 commit intomoby:masterfrom
tonistiigi:git-windows-conf-fix

Conversation

@tonistiigi
Copy link
Copy Markdown
Member

fix #6567

Use a Windows-specific empty temp file for GIT_CONFIG_GLOBAL while keeping the existing null-device HOME behavior on non-Windows. Preserve the current SSH command handling and add focused gitutil coverage for the config-path behavior.

Comment thread util/gitutil/git_cli.go Outdated
"HOME=/dev/null", // Disable reading from user gitconfig.
"LC_ALL=C", // Ensure consistent output.
}
if runtime.GOOS == "windows" {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that this works with just GIT_CONFIG_GLOBAL=os.DevNull but I have no way to verify.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on a Windows host with Git for Windows (git 2.46.0.windows.1), and the fix direction looks right. HOME=/dev/null still breaks there, while HOME=NUL plus an explicit GIT_CONFIG_GLOBAL avoids the global config lookup failure.

And the temp file doesn't seem necessary. GIT_CONFIG_GLOBAL= + os.DevNull also appears to work on Windows in my local probes, so GIT_CONFIG_GLOBAL=os.DevNull may be enough and would avoid creating and cleaning up a temp file for every git invocation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not directly related but I have this PR to support git host config: #6624

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that, I removed the whole windows specific condition and just set GIT_CONFIG_GLOBAL everywhere.

Avoid global conf lookup via HOME that fails on Windows.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@tonistiigi tonistiigi force-pushed the git-windows-conf-fix branch from 37338e6 to e6e6026 Compare April 2, 2026 00:39
Copy link
Copy Markdown
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crazy-max crazy-max added this to the v0.30.0 milestone Apr 2, 2026
@crazy-max crazy-max merged commit 035681e into moby:master Apr 2, 2026
191 checks passed
rzlink pushed a commit to rzlink/buildkit that referenced this pull request Apr 13, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request Apr 13, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request Apr 22, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request Apr 23, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request Apr 28, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink added a commit to rzlink/buildkit that referenced this pull request May 1, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request May 4, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request May 5, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request May 6, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request May 7, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rzlink pushed a commit to rzlink/buildkit that referenced this pull request May 8, 2026
On Windows ARM64, git cannot use the NUL device as HOME or
GIT_CONFIG_GLOBAL path, failing with "fatal: unable to access
'NUL': Invalid argument". This was introduced by e6e6026
(PR moby#6639) which changed HOME=/dev/null to HOME=os.DevNull.

Add platform-specific helpers: on Unix, continue using /dev/null;
on Windows, lazily create an empty temp directory for HOME and an
empty temp file for GIT_CONFIG_GLOBAL.

Signed-off-by: rzlink <nicklin@microsoft.com>

Co-authored-by: Copilot <223556219+Copilot@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.

ADD fails to add Git repository on Windows: unable to access '\\.\GLOBALROOT\Device\Null/.config/git/config': Invalid argument

2 participants