Skip to content

chore: migrate from husky to native git 2.54 config-based hooks#3415

Open
jevonearth wants to merge 1 commit into
mainfrom
chore/migrate-husky-to-native-hooks
Open

chore: migrate from husky to native git 2.54 config-based hooks#3415
jevonearth wants to merge 1 commit into
mainfrom
chore/migrate-husky-to-native-hooks

Conversation

@jevonearth
Copy link
Copy Markdown
Collaborator

Summary

Replaces husky with Git's built-in config-based hooks (Git 2.54+, release notes). The single pre-commit hook (npm run precommit) now lives in a tracked .githooks.config, wired into .git/config via include.path by a prepare script.

  • Removes husky devDependency (net -1 package; husky 9 has zero transitives).
  • No more .husky/_/husky.sh shell-sourcing dance.
  • Hook commands stay tracked and reviewable in the repo.

Behavior details

Old Git handling. scripts/setup-hooks.sh warns to stderr and exits 0 on Git < 2.54 instead of failing. Needed because ubuntu-latest currently ships Git 2.53, so npm ci would otherwise fail in CI before build/test. Contributors on old Git see a loud message explaining why hooks won't run.

core.hooksPath safety. Only unset when it equals .husky/_ (the old husky pointer). Any other value — including a contributor's intentional custom hook directory — is left alone.

Idempotent. Repeat npm install runs don't duplicate the include.path entry.

Tarball/CI-without-.git safety. If there's no .git directory, the script exits 0 cleanly.

Verify

git --version              # need >= 2.54 for hooks to run
npm install                # prepare script wires things up
git hook list pre-commit   # should show "precommit"

Disable locally without editing the config:

git config --local hook.precommit.enabled false

Test plan

  • Fresh clone + npm install wires include.path; git hook list pre-commit shows precommit
  • Committing runs the full workspace precommit (lint-staged fanout), blocks on failure
  • Second npm install run does not duplicate include.path
  • With core.hooksPath=.husky/_, script unsets it
  • With core.hooksPath=/some/user/path, script leaves it alone
  • No .git present → script exits 0
  • CI green on ubuntu-latest (Git 2.53) — prepare should warn + exit 0, not fail

Replace husky with Git's built-in [hook "..."] config mechanism (Git
2.54+). The pre-commit hook now lives in .githooks.config, wired into
.git/config via include.path by scripts/setup-hooks.sh, which runs as
the prepare script on npm install.

- Removes husky devDependency (-1 dep, zero transitives; husky 9 has no
  runtime deps).
- Script warns and exits 0 on Git < 2.54 so npm ci still passes on
  older runners (e.g. ubuntu-latest currently ships Git 2.53).
- Only unsets core.hooksPath if it points at the old .husky/_ path,
  preserving any custom hook directory the contributor has set.
- Idempotent: repeat runs don't duplicate the include.path entry.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.03%. Comparing base (22cabdc) to head (23c646b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3415   +/-   ##
=======================================
  Coverage   80.03%   80.03%           
=======================================
  Files         250      250           
  Lines       14928    14928           
  Branches     3682     3682           
=======================================
  Hits        11948    11948           
  Misses       2980     2980           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants