fix(patch): exclude .git when copying tarballs into the rebase repo #10143

Open
rootvector2 opened 2:56am on October 20, 2026 wants to merge 70 Ξ” into npm/cli latest from
patch-update-strip-dotgit
Diff Delta:
70
About 17 Diff Delta/hour
Classified as:  General

rootvector2's Description of Work

npm patch update rebases the existing patch in a throwaway git repo. #rebasePatch extracts the base and target dependency versions with pacote and copies each tree into that repo with fs.cp. pacote keeps a tarball's own .git/ on extract, so a dependency can ship an executable .git/hooks/pre-commit (or a .git/config with core.fsmonitor) that the copy lays over the work repo, and the git add/git commit right after run it. A publisher of a package you patch then gets code execution the moment you run npm patch update on it, with no install-script prompt in the path.

The copy that goes the other way (repo into the edit dir) already filters .git with notGitDir; the two copies into the repo did not. Pass the same filter to both so a tarball's .git never reaches the rebase repo.

Added a regression test that serves a 2.0.0 tarball carrying an executable pre-commit hook; it runs on the current tree and does not after the fix.

2 total changed files
Loading changes...
That’s the last hunk
The diff well is dry.