Repository navigation
pre-commit's stash restore of untracked files fires the user's post-checkout hook, starting a nested hk #1863
What were you trying to do when you hit this?I have configured I did normal operations with Bellow is my part of conversation with Claude which may help you understand the issue better. I'm sorry for copying it here, but I don't think I can rewrite it better preserving proper details. Feel free to skip it and go to reproduction section at "What you ran".
Also a Claude's summary of the issue, more terse:
What you ranI composed (with help of Claude obviously) a reproduction: mkdir repro && cd repro && git init -q -b main
cat > hk.pkl <<'EOF'
amends "package://github.com/jdx/hk/releases/download/v2.8.1/hk@2.8.1#/Config.pkl"
hooks {
["pre-commit"] {
stash = "git"
steps { ["noop"] = new Step { check = "true" } }
}
["post-checkout"] {
steps { ["marker"] = new Step { check = "echo POST-CHECKOUT RAN" } }
}
}
EOF
echo a > tracked.txt && git add -A && HK=0 git commit -qm init
hk install
echo b >> tracked.txt && git add tracked.txt
echo u > untracked.txt # the trigger
HK_LOG_FILE_LEVEL=debug git commit -qm changeWhat happenedOutputβ― gc
hk 2.8.1 by @jdx β pre-commit β fix [====================================================================================================================================================================================] 1/1
βοΈ stash β Stashed unstaged changes (6 files)
βοΈ mise
hk 2.8.1 by @jdx β pre-commit β fix [====================================================================================================================================================================================] 1/1
βοΈ stash β Stashed unstaged changes (6 files)
βοΈ mise
hk 2.8.1 by @jdx β pre-commit β fix [====================================================================================================================================================================================] 1/1βοΈ stash β Stashed unstaged changes (6 files)
βοΈ mise
β’ ensure-maven-deps-downloaded β skipped: profile not enabled (ci)
β’ aggregate β skipped: profiles not enabled (ci, gitlab)
βοΈ stash β Restoring unstaged changes (manual)
Aborting commit due to empty commit message.Expected OutputThis is taken from the case where bug does not appear. β― gc
hk 2.8.1 by @jdx β pre-commit β fix [====================================================================================================================================================================================] 1/1
βοΈ stash β Stashed unstaged changes (6 files)
βοΈ mise
β’ ensure-maven-deps-downloaded β skipped: profile not enabled (ci)
β’ aggregate β skipped: profiles not enabled (ci, gitlab)
βοΈ stash β Restoring unstaged changes (manual)
Aborting commit due to empty commit message.Log
Claude's suggested fixDon't know whether it will be useful or not, but I hope it could help better understand the issue.
Please, let me know if you need more other information or something else to help chase the issue! Versionhk 2.8.1 (also seen with 2.8.0), installed via mise; git 2.56.0, config-based hooks from hk install ( |
Replies: 2 comments 1 reply
|
I checked nested runs on
Below are my hook declarations, JIC. hooks {
["pre-commit"] {
fix = true
stash = "git"
// The launcher hk installs runs pre-commit with --from-hook --staged, for which hk applies this
// hook's stash setting: unstaged hunks are stashed while the steps run, so spotless:apply works
// on the tree as staged. Its output is left unstaged and rejects the commit, for the developer
// to review and stage.
stage = false
fail_on_fix = true
}
["pre-push"] {
steps {
["ensure-maven-present"] = ensureMavenPresent
["test-compile"] = testCompile
}
}
["post-checkout"] {
steps {
["install-deps"] = (installDeps) {
step_condition = "is_branch_checkout"
}
}
}
["post-merge"] {
steps {
["install-deps"] = installDeps
}
}
["post-rewrite"] {
steps {
["install-deps"] = installDeps
}
}
} |
|
Thanks for the reproduction and the before/after on 2.12 and 2.13. They made this quick to pin down. It's fixed in #1869, which ships in the next release (v2.14.0). The fix is the first one you suggested. hk now sets AI-assisted β Tool: Claude Code; model: anthropic/claude-opus-5-5; version: unavailable. |
Thanks for the reproduction and the before/after on 2.12 and 2.13. They made this quick to pin down. It's fixed in #1869, which ships in the next release (v2.14.0).
The fix is the first one you suggested. hk now sets
HK=0on thegit restorethat puts untracked files back from the stash. The launchershk installwrites already exit whenHK=0, so no second hk starts. Hooks that aren't hk's still run as before. A new test commits with an untracked file and apost-checkoutstep, and it confirms the step no longer runs.AI-assisted β Tool: Claude Code; model: anthropic/claude-opus-5-5; version: unavailable.