mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-07 08:47:11 -04:00
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
This commit is contained in:
committed by
Zoltan Kochan
parent
c716415ac4
commit
982c99944d
12
.changeset/fix-patch-commit-home-env.md
Normal file
12
.changeset/fix-patch-commit-home-env.md
Normal file
@@ -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
|
||||
@@ -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'
|
||||
@@ -159,9 +160,14 @@ async function diffFolders (folderA: string, folderB: string): Promise<string> {
|
||||
// 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,
|
||||
|
||||
Reference in New Issue
Block a user