Skip to content

v2.14.0: Secret scanning across pushed commits, recheck_after_fix, and new builtins

Latest

Choose a tag to compare

@github-actions github-actions released this 23 Nov 22:49
· 6 commits to main since this release
Immutable release. Only release title and notes can be modified.
7beec88

hk 2.14.0 lets secret scanners check every commit in a push. It adds an opt-in recheck_after_fix setting so a check runs again when a later fixer changes its files, and it adds the bun_fmt, keep_sorted, cspell, cspell_commit_message and hk_validate builtins. It also fixes bugs in stash handling, --mise launchers and stdin formatters.

Added

  • Scan every pushed commit for secrets (#1880, @jdx). Before, a scanner on pre-push only checked the final state of the files. A credential added in one commit and removed in a later one passed, even though the push still sent the first commit. gitleaks, betterleaks, trufflehog and kingfisher now accept scan = "commits", which scans each commit in the run's ref range (pre-push, --from-ref or --pr):

    hooks {
        ["pre-push"] {
            steps {
                ["gitleaks"] = (Builtins.gitleaks) { scan = "commits" }
            }
        }
    }

    The default scan for each builtin is unchanged. This change also adds a requires_ref_range step field. When a step sets it and the run has no ref range, the step fails with an error such as gitleaks: needs a ref range (pre-push, --from-ref, or --pr) instead of scanning nothing and passing. Step tests can now set from_ref and to_ref.

  • scan = "staged" for betterleaks (#1878, @jdx). This option works like the one on gitleaks. It runs betterleaks git --pre-commit --staged on the index, so a partially staged file is checked as it will be committed. It ignores hk's file selection, so use it in pre-commit rather than with hk check --all. The default (scan = "files") is unchanged.

  • recheck_after_fix setting (#1891, @jdx). Steps in a fix run (hk fix, or a pre-commit hook with fix = true) run in parallel. A check could pass on a file before another step's fixer rewrote it, and nothing checked the new contents. With this setting on, hk runs such a check again after all steps finish if a fixer changed the contents of a file the check had passed on. The run fails if the new contents no longer pass. Turn it on with any of these:

    • recheck_after_fix = true in hk.pkl or ~/.hkrc.pkl
    • HK_RECHECK_AFTER_FIX=1
    • git config hk.recheckAfterFix true

    The setting is off by default because it adds file reads to every fix run. Each check runs at most once more, and the second runs keep the original group order, depends and exclusive. Steps with check_first are not rerun. hk check is unaffected.

  • New builtins:

    • bun_fmt runs Bun's built-in formatter for hk check, hk fix and hk check --diff. It passes --no-script so a fmt script in package.json can't replace the formatter. hk detects it from bunfig.toml, bun.lock or bun.lockb (#1870, @jdx).
    • keep_sorted checks and sorts the lines between keep-sorted start and keep-sorted end markers (#1898, @jdx).
    • cspell spell-checks text files and follows the project's cspell config. It has no fixer (#1898, @jdx).
    • cspell_commit_message spell-checks the message in a commit-msg hook. It skips git's comment lines and, with git commit --verbose, the diff below the scissors line (#1898, @jdx).
    • hk_validate runs hk validate --deny-warnings when hk.pkl or .config/hk.pkl changes, so config warnings fail the hook (#1862, @jdx).
    hooks {
      ["pre-commit"] {
        fix = true
        steps {
          ["keep-sorted"] = Builtins.keep_sorted
          ["cspell"] = Builtins.cspell
          ["hk_validate"] = Builtins.hk_validate
        }
      }
      ["commit-msg"] {
        steps { ["cspell"] = Builtins.cspell_commit_message }
      }
    }

Changed

  • ox_lint reports diagnostics (#1871, @jdx). The check command now runs oxlint --deny-warnings --format sarif, so oxlint findings appear in hk check --sarif and JSON output. As a result, a failing ox_lint check now prints SARIF JSON instead of oxlint's human-readable report. fix is unchanged.
  • to_ref defaults to HEAD (#1880, @jdx). When only --from-ref is given, {{to_ref}} and HK_TO_REF are now HEAD instead of empty.

Fixed

  • Stash recovery no longer stalls behind a nested hk (#1852, @jdx). After an interrupted run, recovering a stash that contained untracked files triggered post-checkout. If post-checkout ran hk, that second hk waited on the stash lock until HK_STASH_LOCK_TIMEOUT (300 s by default) before the commit could go through. The nested hk now skips its own recovery check.
  • Stash restore no longer starts a nested hk (#1869, @jdx). With stash = "git", restoring an untracked file ran post-checkout, which started a second hk inside the stash window. hk now sets HK=0 for that restore. Hooks that aren't managed by hk still run.
  • Intent-to-add files stay out of commits with stash = "none" (#1884, @jdx). With the default libgit2 backend, files marked with git add -N were treated as staged. Steps received them in {{files}}, and changes a fixer made to them were committed. hk now leaves them out, as git does and as hk already did with stash = "git" or HK_LIBGIT2=0.
  • --mise launchers work without mise on PATH. Git clients that start with a minimal PATH, such as GUIs, IDEs and agent shells, could fail with mise: command not found:
    • The global hk install --global --mise launcher now adds mise's directory to the end of PATH, so steps that call mise run ... work (#1875, @jdx).
    • The per-repo hk install --mise launcher now records mise's absolute path at install time and adds the same PATH entry, for both config hooks and --legacy shims (#1883, @jdx). Run hk install --mise again to update existing hooks. mise must be on PATH while you run the install.
  • Empty files stay empty with stdin formatters (#1874, @jdx). hk fix with tofu (and other builtins that format through hk util format-diff, such as terraform) wrote a newline into intentionally empty files. hk now treats an empty file as unchanged when the formatter outputs only whitespace for it.
  • GIT_WORK_TREE is set only for steps with dir (#1889, @jdx). Before, every hook step received GIT_WORK_TREE. A step that ran git init elsewhere could then write core.worktree into the repository's config. In a linked worktree, that config is shared, so the main checkout was silently repointed. Steps without dir now see the same environment as a plain git hook. The new "Git environment variables in steps" docs section covers the remaining GIT_DIR pitfall.

Security

  • Updated the url crate to 2.5.9 to address RUSTSEC-2026-0592 (#1893, @jdx).

Full Changelog: v2.13.0...v2.14.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.