From cb49a64af753550800d78ee9b1a72c179bd3d63a Mon Sep 17 00:00:00 2001 From: Umesh More <73871036+umeshmore45@users.noreply.github.com> Date: Sat, 28 Feb 2026 06:07:37 +0530 Subject: [PATCH] fix(patch): prevent git config path errors in patch-commit (#10640) * 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 --- .changeset/fix-patch-commit-home-env.md | 12 ++++++++++++ patching/plugin-commands-patching/src/patchCommit.ts | 12 +++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 .changeset/fix-patch-commit-home-env.md diff --git a/.changeset/fix-patch-commit-home-env.md b/.changeset/fix-patch-commit-home-env.md new file mode 100644 index 0000000000..51673c4c52 --- /dev/null +++ b/.changeset/fix-patch-commit-home-env.md @@ -0,0 +1,12 @@ +--- +"@pnpm/plugin-commands-patching": patch +"pnpm": patch +--- + +Fixed `pnpm patch-commit` failing with "unable to access '/.config/git/attributes': Permission denied" error in environments where HOME is unset or non-standard (Docker containers, CI systems). + +The issue occurred because pnpm 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`. + +Now uses `GIT_CONFIG_GLOBAL: os.devNull` instead, which is git's proper mechanism for bypassing user-level configuration without corrupting the home directory path resolution. + +Fixes #6537 \ No newline at end of file diff --git a/patching/plugin-commands-patching/src/patchCommit.ts b/patching/plugin-commands-patching/src/patchCommit.ts index 63ac7c90d9..d1ad2fd8f8 100644 --- a/patching/plugin-commands-patching/src/patchCommit.ts +++ b/patching/plugin-commands-patching/src/patchCommit.ts @@ -1,4 +1,5 @@ import fs from 'fs' +import os from 'os' import path from 'path' import { docsUrl } from '@pnpm/cli-utils' import { type Config, types as allTypes } from '@pnpm/config' @@ -158,9 +159,14 @@ async function diffFolders (folderA: string, folderB: string): Promise { // These variables aim to ignore the global git config so we get predictable output // https://git-scm.com/docs/git#Documentation/git.txt-codeGITCONFIGNOSYSTEMcode GIT_CONFIG_NOSYSTEM: '1', - HOME: '', - XDG_CONFIG_HOME: '', - USERPROFILE: '', + // Redirect the global git config to the null device instead of setting + // HOME to an empty string. An empty HOME causes git to resolve '~' as + // '/' (root), which triggers a "Permission denied" warning when git + // tries to access '/.config/git/attributes', making pnpm throw an + // error because any stderr output is treated as a failure. + // We do not set XDG_CONFIG_HOME to avoid the same issue: an empty + // value would make git resolve paths like /git/config and /git/attributes. + GIT_CONFIG_GLOBAL: os.devNull, // #endregion }, stripFinalNewline: false,