github jdx/hk v2.12.0
v2.12.0: Restrict conventional commit scopes

42 minutes ago

hk 2.12.0 lets the check_conventional_commit builtin restrict which scopes a commit can use. It also fixes three bugs: misleading errors when a run is stopped by SIGTERM or SIGHUP, missing hooks after hk install --legacy on top of a global install, and stash restore failures caused by another linked worktree.

Added

  • Allowed scopes for conventional commits (#1817, @jonahsnider). Set allowed_scopes on check_conventional_commit to limit which scopes commit messages can use:

    ["conventional-commit"] = (Builtins.check_conventional_commit) {
      allowed_scopes = List("web", "api")
    }

    Commits without a scope are always accepted. A commit with any other scope is rejected, and the error lists the allowed scopes. If you omit allowed_scopes, any scope is accepted. To accept only commits without a scope, set allowed_scopes = List(). Each list entry must hold one scope, with no commas. The same option is available directly as hk util check-conventional-commit --allowed-scopes web,api.

Fixed

  • Clearer message when a run is stopped by SIGTERM or SIGHUP (#1814, @jdx). When an external signal stopped hk, such as a job supervisor's deadline, the hook error named whichever step was running with "command was cancelled". That made the step look like it had failed. hk now names the signal instead, for example stopped by SIGTERM before the run finished (no step failed); exit 143. Exit codes are unchanged (143 for SIGTERM, 129 for SIGHUP). Ctrl-C output and real step failures are also unchanged.
  • hk install --legacy after a global install (#1828, @jdx). If hk install --global had already written hook.hk-* entries, hk install --legacy printed "skipping local install" and wrote nothing. Git versions older than 2.54 don't read config-based hooks, so commits there ran with no hook and no error. With --legacy, hk now installs the .git/hooks/ shims even when a global install exists. Plain hk install does the same when the git on PATH is older than 2.54. On git 2.54+, having both global hooks and shims makes hk run twice per event. Without --legacy, git 2.54+ still skips the local install, and --force-local still overrides the skip.
  • Stash restore across linked worktrees (#1827, @jdx). With stash = "git", a commit could fail at the restore step with bad revision 'refs/stash' and failed to restore stash. This happened when another linked worktree emptied the shared stash stack while the hook ran. No work was lost, but unstaged and untracked changes stayed stashed until you recovered them by hand. hk now looks up its entry on its private ref refs/hk/stash/<commit> first, so races on the shared stack no longer affect those entries. Entries that older hk versions pushed to the shared stack can still hit the race.

New Contributors

Full Changelog: v2.11.1...v2.12.0

💚 Sponsor hk

hk is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.

If hk speeds up your pre-commit loop or makes linting less painful, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep hk fast, free, and independent.

Don't miss a new hk release

NewReleases is sending notifications on new releases.