Skip to content

Version-bump detection in .hooks/pre-commit should compare old vs new value #592

Description

@vivek7405

Problem

.hooks/pre-commit detects a staged version bump by scanning git diff --cached --unified=0 for an ADDED "version": "..." line in any packages/*/package.json (the STAGED_PKG_BUMPS awk, ~L54-63). With --unified=0, an edit ADJACENT to the version line (e.g. adding a sibling field right after "version") re-emits the version line as a + line even when the version did NOT change. That spuriously registers a "bump", which then:

So a legit non-version edit to a published package's package.json, made immediately adjacent to the version line on a feature branch, is rejected. Escape is --no-verify, but it is a surprising false-positive.

Design / approach

Make the detection compare the NEW version value against the committed (HEAD) value, and treat it as a bump only when they differ. Roughly: for each packages/<dir>/package.json in the staged diff, read the new staged version (git show :<path> or the working file) and the old (git show HEAD:<path>), and emit <pkg>@<newver> only if old != new. This fixes BOTH gate 2 (changelog) and gate 3 (release-branch guard) since both read STAGED_PKG_BUMPS.

Implementation notes (for the implementing agent)

  • Where: .hooks/pre-commit, the STAGED_PKG_BUMPS awk block (~L54-63). Replace the "any added version line" heuristic with an old-vs-new comparison per changed package.json. Keep the output shape (<dir>@<version>) so gate 2 + gate 3 are unchanged downstream.
  • Map dirs the same way the current awk does (packages/editors/intellisense -> intellisense, etc.).
  • Landmines: a NEWLY-ADDED package.json has no HEAD:<path> (treat as a bump or skip, decide deliberately). Preserve the $GITHUB_ACTIONS bot-skip and main-block. Invariant 11 in any new comments.
  • Tests: extend test/hooks/release-branch-guard.test.mjs with a case that stages a non-version edit adjacent to the version line on a feature branch and asserts the hook does NOT block (currently it would). Counterfactual: a real version change still registers.

Acceptance criteria

  • A non-version edit to a published package's package.json (even adjacent to the version line) on a feature branch is NOT blocked.
  • A real version change is still detected (gate 2 generates the changelog; gate 3 still guards off release branches).
  • Test covers both, with a counterfactual.

Activity

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions