Skip to content

fix(patch): prevent git config path errors in patch-commit#10640

Merged
zkochan merged 2 commits intopnpm:mainfrom
umeshmore45:fix/patch-commit-home-env
Feb 28, 2026
Merged

fix(patch): prevent git config path errors in patch-commit#10640
zkochan merged 2 commits intopnpm:mainfrom
umeshmore45:fix/patch-commit-home-env

Conversation

@umeshmore45
Copy link
Copy Markdown
Contributor

@umeshmore45 umeshmore45 commented Feb 18, 2026

Problem

pnpm patch-commit fails with "Permission denied" when trying to access /.config/git/attributes in environments where HOME is unset or points to a restricted path (Docker containers, CI systems).

Error:

ERROR Unable to diff directories
warning: unable to access '/.config/git/attributes': Permission denied

Root Cause

The code was setting HOME: '' and USERPROFILE: '' to suppress user git configuration when running git 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 device

This 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-index using 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

Replace HOME='' with GIT_CONFIG_GLOBAL to bypass user config
without breaking home directory resolution in restricted environments.

Fixes pnpm#6537
Copilot AI review requested due to automatic review settings February 18, 2026 19:43
@umeshmore45 umeshmore45 requested a review from zkochan as a code owner February 18, 2026 19:43
@welcome
Copy link
Copy Markdown

welcome bot commented Feb 18, 2026

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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: '' and USERPROFILE: '' with GIT_CONFIG_GLOBAL: os.devNull to properly bypass git user configuration without corrupting path resolution
  • Added os import to support os.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: '',
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Use GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL to bypass git config
without breaking HOME path resolution in restricted environments.

Fixes pnpm#6537
@zkochan zkochan merged commit cb49a64 into pnpm:main Feb 28, 2026
3 of 5 checks passed
@welcome
Copy link
Copy Markdown

welcome bot commented Feb 28, 2026

Congrats on merging your first pull request! 🎉🎉🎉

zkochan pushed a commit that referenced this pull request Mar 7, 2026
* 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
zkochan pushed a commit that referenced this pull request Mar 7, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm patch-commit raises git error ("permission denied" )

3 participants