github jdx/hk v1.42.0
v1.42.0: Hook args template and Windows quoting fix

14 hours ago

This release adds a new {{ hook_args }} template variable for forwarding git hook arguments to downstream commands, and fixes a Windows-specific bug where {{files}} expansion silently broke file-based checks.

Added

  • {{ hook_args }} template variable: Step commands can now access the arguments that git passes to hook scripts via {{ hook_args }}. This is essential for tools like git-lfs, whose hooks (post-checkout, post-merge, pre-push) require the original positional arguments from git to function correctly. Without this, commands like git lfs post-checkout would fail with "This should be run through Git's post-checkout hook." (@JohanLorenzo) #807

    hooks {
        ["post-checkout"] {
            steps {
                ["git-lfs"] { check = "git lfs post-checkout {{ hook_args }}" }
            }
        }
        ["post-merge"] {
            steps {
                ["git-lfs"] { check = "git lfs post-merge {{ hook_args }}" }
            }
        }
        ["pre-push"] {
            steps {
                ["git-lfs"] { check = "git lfs pre-push {{ hook_args }}" }
            }
        }
    }

    The variable is populated for all hook types: pre-push gets <remote-name> <remote-url>, commit-msg gets the message file path, post-checkout gets <prev-head> <new-head> <is-branch>, and so on. For hooks that receive no arguments (like pre-commit), it expands to an empty string.

  • First-class post-checkout, post-merge, and post-rewrite hooks: These three hook types now have dedicated subcommands (hk run post-checkout, hk run post-merge, hk run post-rewrite) with proper argument parsing, rather than being handled as generic hooks. (@JohanLorenzo) #807

Fixed

  • {{files}} expansion on Windows no longer silently breaks checks: On Windows, Rust's Command::arg applies MSVCRT-style argv escaping that collides with cmd.exe's own quoting rules. This caused the already-quoted {{files}} payload to reach tools with literal " characters embedded in arguments. Tools like ruff, biome, and others would silently exit 0 while processing zero files, making hk report success on broken invocations. The fix switches the Windows cmd.exe /c code path to use raw_arg, passing the rendered command string verbatim so cmd.exe can parse its own quoting without Rust interference. This also affects {{workspace_files}}. (@jdx) #824

New Contributors

Full Changelog: v1.41.1...v1.42.0

Don't miss a new hk release

NewReleases is sending notifications on new releases.