chore: add pre-push hook guarding yarn.lock drift - #1220
Open
Martin Hochel (Hotell) wants to merge 1 commit into
Open
chore: add pre-push hook guarding yarn.lock drift#1220Martin Hochel (Hotell) wants to merge 1 commit into
Martin Hochel (Hotell) wants to merge 1 commit into
Conversation
CI runs `yarn install --immutable`, but that check only ever inspects the working tree. A lockfile that was regenerated locally and never committed therefore passes locally and fails on CI, which is exactly what happened in microsoft#1219. The hook closes both gaps: - `git diff --quiet HEAD -- yarn.lock` rejects a lockfile that differs from the commit being pushed (staged or unstaged) - `yarn install --immutable` rejects a manifest change, including peerDependencies, with no matching lockfile update Both are no-ops when everything is in sync.
📋 PR Validation SummaryCheck the Build react library job summary for detailed reports:
|
There was a problem hiding this comment.
Pull request overview
Adds a Husky pre-push hook to prevent pushing when yarn.lock has drifted locally (including the “lockfile regenerated but not committed” case that yarn install --immutable alone won’t catch), aligning local checks with CI expectations.
Changes:
- Add
.husky/pre-pushhook that blocks pushes whenyarn.lockdiffers fromHEAD. - Run
yarn install --immutableduringpre-pushto catch manifest/lockfile mismatches before pushing.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Martin Hochel (Hotell)
marked this pull request as ready for review
August 24, 2026 09:48
Martin Hochel (Hotell)
requested review from
a team and
Victor Genaev (mainframev)
August 24, 2026 09:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CI runs
yarn install --immutable, but that check only ever inspects the working tree.A lockfile that was regenerated locally and never committed therefore passes locally and
fails on CI.
That is exactly what happened in #1219:
peerDependencieswere edited afteryarn add,the lockfile was regenerated at some later point but the commit kept the stale copy, and
a local
yarn install --immutablestill reported success because it was validating therepaired working tree rather than the commit.
The gap
Two distinct failure modes exist, and
--immutableonly covers one:--immutable?Change
A
.husky/pre-pushhook covering both:The git check runs first because it is essentially free;
--immutableis a read-onlyno-op when the tree is already in sync, so the hook adds no meaningful cost to a normal push.
Note that
git status --porcelainis unsuitable here: it exits0even when it printsoutput, so it cannot gate a hook.
git diff --quiet HEADreturns non-zero and covers bothstaged and unstaged drift.
Verification
yarn.lockmodified but uncommittedyarn.lock differs from HEADpeerDependenciesadded with stale lockYN0028This PR's own push exercised the hook.