Repository navigation
pre-commit's stash restore of untracked files fires the user's post-checkout hook, starting a nested hk #1863
Unanswered
zekefast
asked this question in
Troubleshooting and Bug Reports
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
}
}
} |
0 replies
|
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. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What were you trying to do when you hit this?
I have configured
post-checkout,post-rewrite,post-merge,pre-pushand obviouslypre-commithooks.I did normal operations with
git, like stashing/unstashing and committing changes and noticed that sometimes I seehk's progress bar several times. At first I thought it is just terminal output glitch. I researched it with Claude and it turns out it looks likehkfires nested hooks, i.e.hkwas fired already by my operation withgitand thenhkstarts firing itself.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 ran
I composed (with help of Claude obviously) a reproduction:
What happened
Output
Expected Output
This 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
.git/hk/hk.logshows two processes; the second starts right after the restore:Claude's suggested fix
Don'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!
And thank you for the very awesome tool! I definitely feel I try to overuse it but weirdly enough the more I learn it the more I can go with my crazy automation of huge Java code base. And thanks for the mise as well! Another crazy tool that I can't stop using and finding the gems in it!
Version
hk 2.8.1 (also seen with 2.8.0), installed via mise; git 2.56.0, config-based hooks from hk install (
hook.hk-*.command); macOS 26 (arm64); the mechanism is git's, not platform-specificAll reactions