mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 09:55:39 -04:00
## Summary Fixes `pnpm install` with `optimisticRepeatInstall` incorrectly returning `Already up to date` when `pnpm-lock.yaml` changed but project manifests did not. Fixes #12100. ## Root Cause `checkDepsStatus` used modified manifest mtimes as the only signal for whether it needed to validate dependency status. If no manifest was newer than `workspaceState.lastValidatedTimestamp`, it returned `upToDate: true` before checking whether the wanted lockfile had changed. That skipped lockfile validation for workflows like: - `git checkout HEAD~1 -- pnpm-lock.yaml` - restoring only `pnpm-lock.yaml` from a stash - external tools rewriting the lockfile without touching manifests ## Changes - Check wanted lockfile mtimes before taking the optimistic fast path. - If any wanted lockfile is missing or newer than the workspace state timestamp, validate all projects instead of only modified manifests. - Add a regression test proving a lockfile-only change does not skip wanted-lockfile validation. - Add a patch changeset for `@pnpm/deps.status` and `pnpm`. --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { expect, test } from '@jest/globals'
|
|
import { getCurrentBranch, isGitRepo, isWorkingTreeClean } from '@pnpm/network.git-utils'
|
|
import { safeExeca as execa } from 'execa'
|
|
import { temporaryDirectory } from 'tempy'
|
|
|
|
test('isGitRepo', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
process.chdir(tempDir)
|
|
|
|
await expect(isGitRepo()).resolves.toBe(false)
|
|
|
|
await execa('git', ['init'])
|
|
|
|
await expect(isGitRepo()).resolves.toBe(true)
|
|
})
|
|
|
|
test('getCurrentBranch', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
process.chdir(tempDir)
|
|
|
|
await execa('git', ['init'])
|
|
await execa('git', ['checkout', '-b', 'foo'])
|
|
|
|
await expect(getCurrentBranch()).resolves.toBe('foo')
|
|
})
|
|
|
|
test('getCurrentBranch reads branch from .git/HEAD without spawning git', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
|
|
await execa('git', ['init'], { cwd: tempDir })
|
|
await execa('git', ['checkout', '-b', 'bar'], { cwd: tempDir })
|
|
|
|
await expect(getCurrentBranch({ cwd: tempDir })).resolves.toBe('bar')
|
|
})
|
|
|
|
test('getCurrentBranch returns null for detached HEAD', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
|
|
await execa('git', ['init'], { cwd: tempDir })
|
|
await execa('git', ['checkout', '-b', 'main'], { cwd: tempDir })
|
|
await execa('git', ['config', 'user.email', 'test@test.com'], { cwd: tempDir })
|
|
await execa('git', ['config', 'user.name', 'test'], { cwd: tempDir })
|
|
await execa('git', ['config', 'commit.gpgsign', 'false'], { cwd: tempDir })
|
|
await execa('git', ['commit', '--allow-empty', '-m', 'init'], { cwd: tempDir })
|
|
await execa('git', ['checkout', '--detach', 'HEAD'], { cwd: tempDir })
|
|
|
|
await expect(getCurrentBranch({ cwd: tempDir })).resolves.toBeNull()
|
|
})
|
|
|
|
test('getCurrentBranch returns null outside a git repo', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
|
|
await expect(getCurrentBranch({ cwd: tempDir })).resolves.toBeNull()
|
|
})
|
|
|
|
test('isWorkingTreeClean', async () => {
|
|
const tempDir = temporaryDirectory()
|
|
process.chdir(tempDir)
|
|
|
|
await execa('git', ['init'])
|
|
|
|
await expect(isWorkingTreeClean()).resolves.toBe(true)
|
|
|
|
fs.writeFileSync(path.join(tempDir, 'foo'), 'foo')
|
|
|
|
await expect(isWorkingTreeClean()).resolves.toBe(false)
|
|
})
|