Fix global auth when GIT_CONFIG_GLOBAL is set in the environment#2449
Open
nmoinvaz wants to merge 1 commit into
Open
Fix global auth when GIT_CONFIG_GLOBAL is set in the environment#2449nmoinvaz wants to merge 1 commit into
nmoinvaz wants to merge 1 commit into
Conversation
configureTempGlobalConfig isolates global git config by overriding HOME to a temporary directory. But GIT_CONFIG_GLOBAL takes precedence over HOME when git locates the global config file, so when a workflow already has GIT_CONFIG_GLOBAL set in the environment, 'git config --global' writes land in that file instead of the temporary config. replaceTokenPlaceholder then reads the temporary config, cannot find the placeholder, and fails with 'Unable to replace auth placeholder'. Set GIT_CONFIG_GLOBAL to the temporary config alongside the HOME override so global config operations always target the temp file regardless of any inherited value, and unset it again in removeGlobalConfig. Assisted-By: Claude Opus 4.8
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.
Problem
When a checkout sets up global auth (e.g.
submodules: true),configureTempGlobalConfigdoes:~/.gitconfiginto a temp dir and overrideHOMEto point at it.git config --global …, expecting it to land in the temp config (becauseHOMEnow points there).replaceTokenPlaceholder).The catch:
GIT_CONFIG_GLOBALoverridesHOMEwhen git locates the global config file. So if the environment already hasGIT_CONFIG_GLOBALset, step 2 writes to that file instead of the temp config. Step 3 then reads the temp config, doesn't find the placeholder, and fails:checkout only ever overrides
HOME, neverGIT_CONFIG_GLOBAL— so aGIT_CONFIG_GLOBALset by the workflow or runner (a common way to isolate git config per job on self-hosted runners) silently wins.Fix
Pin
GIT_CONFIG_GLOBALto the temporary config alongside the existingHOMEoverride, and unset it again inremoveGlobalConfig. Both env vars then point at the same temp file, so--globaloperations target it regardless of any inherited value. Backward compatible: older git that ignoresGIT_CONFIG_GLOBALstill falls back to theHOMEoverride (same file).How it works
setEnvironmentVariable/removeEnvironmentVariabledon't change the process environment — they edit theGitCommandManager'sgitEnvmap, which is overlaid on top ofprocess.enveach time checkout spawns agitsubprocess:setinconfigureTempGlobalConfigforcesGIT_CONFIG_GLOBAL=<temp>/.gitconfigfor checkout's git commands, shadowing any inherited value — this is the fix.removeinremoveGlobalConfigis teardown that mirrors the existingHOMEcleanup; the fix does not depend on it.Reproduction (real git 2.54)
Inherited
GIT_CONFIG_GLOBALset to a decoy file, simulating checkout'sgit config --globalwrite then the temp-config read:--globalwrite lands inUnable to replace auth placeholderGIT_CONFIG_GLOBALpinned (this PR)Scope
The
HOME-only override predates v6 —configureTempGlobalConfighas the same shape in v4 and v5 — so this affects v4/v5/v6. The fix applies cleanly in each.Tests
configureGlobalAuth overrides GIT_CONFIG_GLOBAL— asserts the override points at the temp config.removeGlobalConfig removes override— extended to assertGIT_CONFIG_GLOBALis unset afterward.dist/index.jsrebuilt vianpm run build.🤖 Generated with Claude Code