fix(patch): prevent git config path errors in patch-commit#10640
fix(patch): prevent git config path errors in patch-commit#10640
Conversation
Replace HOME='' with GIT_CONFIG_GLOBAL to bypass user config without breaking home directory resolution in restricted environments. Fixes pnpm#6537
|
💖 Thanks for opening this pull request! 💖 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where pnpm patch-commit fails with "Permission denied" errors in Docker containers and CI systems. The issue occurred because setting HOME: '' and USERPROFILE: '' caused git to resolve the home directory as root (/), leading to permission errors when git tried to access /.config/git/attributes.
Changes:
- Replaced
HOME: ''andUSERPROFILE: ''withGIT_CONFIG_GLOBAL: os.devNullto properly bypass git user configuration without corrupting path resolution - Added
osimport to supportos.devNull - Added changeset documenting the fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| patching/plugin-commands-patching/src/patchCommit.ts | Updated git environment variables to use GIT_CONFIG_GLOBAL instead of manipulating HOME/USERPROFILE |
| .changeset/fix-patch-commit-home-env.md | Documented the bug fix for the patch release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // tries to access '/.config/git/attributes', making pnpm throw an | ||
| // error because any stderr output is treated as a failure. | ||
| GIT_CONFIG_GLOBAL: os.devNull, | ||
| XDG_CONFIG_HOME: '', |
There was a problem hiding this comment.
Setting XDG_CONFIG_HOME: '' could potentially cause similar permission issues as the original HOME: '' problem. When XDG_CONFIG_HOME is set to an empty string, git will try to access /git/config and /git/attributes (forming paths from the empty string), which may trigger permission errors in restricted environments.
Since GIT_CONFIG_GLOBAL: os.devNull already prevents git from reading user-level config files, consider either removing this line entirely or setting it to os.devNull as well to be consistent with the fix approach. The git commands are using --no-ext-diff and --no-color flags which should prevent most config-based behavior changes anyway.
Use GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL to bypass git config without breaking HOME path resolution in restricted environments. Fixes pnpm#6537
|
Congrats on merging your first pull request! 🎉🎉🎉 |
* fix(patch): prevent git config path errors in patch-commit Replace HOME='' with GIT_CONFIG_GLOBAL to bypass user config without breaking home directory resolution in restricted environments. Fixes #6537 * fix(patch): prevent git config path errors in patch-commit Use GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL to bypass git config without breaking HOME path resolution in restricted environments. Fixes #6537
* fix(patch): prevent git config path errors in patch-commit Replace HOME='' with GIT_CONFIG_GLOBAL to bypass user config without breaking home directory resolution in restricted environments. Fixes #6537 * fix(patch): prevent git config path errors in patch-commit Use GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL to bypass git config without breaking HOME path resolution in restricted environments. Fixes #6537
Problem
pnpm patch-commitfails with "Permission denied" when trying to access/.config/git/attributesin environments where HOME is unset or points to a restricted path (Docker containers, CI systems).Error:
Root Cause
The code was setting
HOME: ''andUSERPROFILE: ''to suppress user git configuration when runninggit diff. This caused git to resolve the home directory (~) as root (/), leading to permission errors when attempting to access/.config/git/attributes.Solution
Replaced environment variable manipulation (
HOME: '',USERPROFILE: '',XDG_CONFIG_HOME: '') with proper git configuration flags:GIT_CONFIG_NOSYSTEM: '1'- Skip system-level config (official git method)GIT_CONFIG_GLOBAL: os.devNull- Redirect global config to null deviceThis approach uses git's documented mechanisms for bypassing configuration without corrupting environment variable path resolution, which was causing git to resolve
~as/(root) and trigger permission errors in restricted environments.Testing
Tested locally with
git diff --no-indexusing both approaches. The fix prevents git from looking for config files without breaking path resolution. CI will validate in Docker environments where the original bug manifests.Closes
Fixes #6537