Skip to content

fix(arborist): require matching commit for non-hosted git pins - #10251

Open
ump45nose wants to merge 1 commit into
npm:latestfrom
ump45nose:fix/10249-git-committish-dep-valid
Open

ump45nose wants to merge 1 commit into
npm:latestfrom
ump45nose:fix/10249-git-committish-dep-valid

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

depValid's git case already refuses to treat two different definite commits as the same dependency when the remote is a hosted provider (hosted.ssh({ noCommittish: !reqCommit })). For non-hosted remotes it only compared fetchSpec, which drops the #committish, so a self-hosted GitLab URL or git+file: pin at commit A incorrectly satisfied an edge pinned to commit B.

Fixes #10249

Changes

  • After the non-hosted fetchSpec equality check, also require resRepo.gitCommittish === requested.gitCommittish when the request is a definite 40–64 hex commit.
  • Unit coverage for self-hosted https, git://, and hosted control cases.

Test plan

  • npx tap --no-coverage test/dep-valid.js in workspaces/arborist (all subtests pass, including the new ones)
  • CI arborist / lint

AI disclosure

This change was prepared with AI assistance. The root cause and reproduction in #10249 were verified locally against current latest before opening the PR; the unit tests encode the same cases called out in the issue body.

depValid's git case compared hosted repos with ssh({ noCommittish }) so a
definite commit pin could not dedupe onto a different SHA, but non-hosted
URLs only compared fetchSpec, which omits the hash. Self-hosted remotes
and git+file: pins then incorrectly shared one commit across edges.

Fixes npm#10249
@ump45nose
ump45nose requested a review from a team as a code owner November 6, 2026 21:24

@ychampion ychampion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked 0781e2c13d against its parent bd8b33909a on Linux / Node 24.22.3.

The full Arborist npm test passes all 59 test files with 100% statement, branch, function and line coverage, plus lint and template checks. The new unit test fails on the parent at both non-hosted commit-mismatch assertions.

I also ran 56 actual CLI commands against disposable local Git repositories, with 28 consumer loads after fresh install and ci. Six mismatching-pin scenarios reproduce the wrong dependency on the parent and load the requested commit on this head: different versions, different commits with the same version, reversed root/child commits, scoped packages, prefer-dedupe, and nested installs. The resulting lockfiles retain both requested SHAs. The identical-commit control still deduplicates.

No blocking finding in the scoped change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Commit-pinned git dependencies on non-hosted repositories are deduplicated across different commits

2 participants