[Bug?]: patch-commit throws when git diff produces warnings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
yarn patch-commit -s /tmp/folder fails if git diff writes warnings to stderr.
To reproduce
It's very simple:
yarn patch packageyarn patch-commit -s /tmp/xfs-some-random-chars/user
❯ yarn patch react-router
➤ YN0000: Package react-router@npm:8.3.1 got extracted with success!
➤ YN0000: You can now edit the following folder: /tmp/xfs-b87290bf/user
➤ YN0000: Once you are done run yarn patch-commit -s /tmp/xfs-b87290bf/user and Yarn will store a patchfile based on your changes.
➤ YN0000: Done in 0s 147ms
❯ yarn patch-commit -s /tmp/xfs-b87290bf/user
Internal Error: Unable to diff directories. Make sure you have a recent version of 'git' available in PATH.
The following error was reported by 'git':
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
The following error was reported by 'git':
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
at xie (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:753:1455)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async cv.execute (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:755:5218)
at async cv.validateAndExecute (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:96:787)
at async t.run (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:100:3263)
at async Njt (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:773:8146)
at async _O (/home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.yarn/releases/yarn-4.18.0.cjs:774:142)
Environment
❯ yarn dlx -q envinfo --preset jest
System:
OS: Linux 7.1 cpe:/o:nixos:nixos:26.05 26.05 (Yarara)
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Binaries:
Node: 24.19.0 - /tmp/xfs-0f115d47/node
Yarn: 4.18.0 - /tmp/xfs-0f115d47/yarn
npm: 11.19.0 - /home/manu/Projects/emanueleperuffo/emanueleperuffo-monorepo2/.devbox/nix/profile/default/bin/npm
I'm not sure why it shows node 24 because I'm in a devbox environment set up by direnv.
❯ node --version
v26.7.0
Additional context
I see that you consider the command failed if stderr is not empty. However those are warnings and not errors.
I tried to run the command that yarn runs directly in cli, first as is, and then by adding 2 more config overrides (-c core.hooksPath=/dev/null -c core.attributesFile=/dev/null) and those 2 config overrides (at least the attributes one, I've added the hooks one just in case) hide the warnings.
I have also tried patching the compiled release file in project/.yarn/releases/yarn-4.18.0.cjs adding those config overrides to the execvp call (await un.execvp("git",["-c","core.hooksPath=/dev/null","-c","core.attributesFile=/dev/null","-c",...) and it makes patch-commit work.
Command as run by yarn:
❯ PAGER="" GIT_CONFIG_NOSYSTEM="1" HOME="" XDG_CONFIG_HOME="" USERPROFILE="" git -c core.safecrlf=false -c core.quotePath=false diff --src-prefix=a/ --dst-prefix=b/ --ignore-cr-at-eol --full-index --no-index --no-renames --text /tmp/xfs-b87290bf/source /tmp/xfs-b87290bf/user
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
warning: unable to access '/.config/git/attributes': Permission denied
diff --git a/tmp/xfs-b87290bf/source/dist/development/index-react-server.js b/tmp/xfs-b87290bf/user/dist/development/index-react-server.js
index 2e9e07c2fdf31a30f3733dec8eb4b586697eeb53..b21c325ea30b5276812304f04df0dc3c459e8af8 100644
--- a/tmp/xfs-b87290bf/source/dist/development/index-react-server.js
+++ b/tmp/xfs-b87290bf/user/dist/development/index-react-server.js
@@ -502,7 +502,7 @@ function encodePathParam(value) {
* @returns A path match object if the pattern matches the pathname,
* or `null` if it does not match.
*/
Command with the 2 additional overrides (doesn't warn anymore):
❯ PAGER="" GIT_CONFIG_NOSYSTEM="1" HOME="" XDG_CONFIG_HOME="" USERPROFILE="" git -c core.hooksPath=/dev/null -c core.attributesFile=/dev/null -c core.safecrlf=false -c core.quotePath=false diff --src-prefix=a/ --dst-prefix=b/ --ignore-cr-at-eol --full-index --no-index --no-renames --text /tmp/xfs-b87290bf/source /tmp/xfs-b87290bf/user
diff --git a/tmp/xfs-b87290bf/source/dist/development/index-react-server.js b/tmp/xfs-b87290bf/user/dist/development/index-react-server.js
index 2e9e07c2fdf31a30f3733dec8eb4b586697eeb53..b21c325ea30b5276812304f04df0dc3c459e8af8 100644
--- a/tmp/xfs-b87290bf/source/dist/development/index-react-server.js
+++ b/tmp/xfs-b87290bf/user/dist/development/index-react-server.js
@@ -502,7 +502,7 @@ function encodePathParam(value) {
* @returns A path match object if the pattern matches the pathname,
* or `null` if it does not match.
*/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the patch-commit command implementation and trace the Git diff invocation shown in the report. Reproduce with the provided yarn patch and yarn patch-commit commands, then verify that Git warnings on stderr no longer make the command fail while genuine diff errors still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, node.js, typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100