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

Pull Request Overview

  • Opened on October 20, 2026
  • Status Open
  • Commit count 1 with first commit October 18, 2026

Total Delta

70 Total Diff Delta

Open Days

Open 13 weekdays

Test Delta

60 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Data pending calculation for pull request

Author avatar

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

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.

No comments have been left on this PR.