Skip to content

fix(stash): stop a stash restore from starting a nested hk through post-checkout - #1869

Merged
jdx merged 1 commit into
mainfrom
fix/stash-restore-nested-hk
Nov 18, 2026
Merged

jdx merged 1 commit into
mainfrom
fix/stash-restore-nested-hk

Conversation

@jdx

@jdx jdx commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Fixes discussion 1863.

When a pre-commit hook with stash = "git" stashed an untracked file, hk put it back with git restore --source=<stash>^3 --worktree -- <file>. Git runs post-checkout for that, so a user with hk installed for post-checkout got a second hk, with its own progress bar, starting inside the first one's stash window.

hk now sets HK=0 on that git restore. The launchers hk install writes already skip hk when HK=0, so the nested hk never starts. Other (non-hk) hooks are untouched.

Before, with a post-checkout step that writes a marker file, committing with an untracked file wrote the marker. Now it does not, and the untracked and unstaged edits are still restored. The new test/stash_restore_no_nested_hk.bats fails without the change and passes with it; the existing nested-recovery test still passes.

🤖 Generated with Claude Code

AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.


Note

Low Risk
Small, targeted env var on an internal git restore during stash; documented HK=0 behavior with a regression test.

Overview
Fixes nested hk runs during git stash restore when post-checkout hooks are installed.

During pre-commit with stash = "git", putting back an untracked file uses git restore, which triggers post-checkout. That could start a second hk inside the first run’s stash window. restore_stashed_path now sets HK=0 on that git restore so the installed launcher skips hk; other git hooks still run.

test/stash_restore_no_nested_hk.bats covers a commit with an untracked file and asserts the post-checkout marker is not created while stash restore still works.

Reviewed by Cursor Bugbot for commit 4cbbbe7. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Git stashing during commits no longer triggers a nested launcher through the post-checkout hook, while preserving staged, unstaged, and untracked changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AI-Assisted: Tool: Claude Code; model: unavailable; version: 2.1.325
Entire-Checkpoint: 01M7P27B7085HQ82R4KR0GMS8H
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The stash restore command sets HK=0 when it runs git restore. A Bats regression test checks that the post-checkout hook does not create a marker during commit and that unstaged and untracked changes are preserved.

Changes: Stash restore

Layer / File(s) Summary
Suppress nested hk during restore
src/git.rs, test/stash_restore_no_nested_hk.bats
The restore command sets HK=0. The Bats test configures stash-based pre-commit behavior and checks that no post-checkout marker appears and that unstaged and untracked content remains.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • jdx/hk#1852: Addresses the same nested-hk path during stash restoration by setting HK_RECOVERING_STASH=1 so nested hk skips its recovery check.

Suggested reviewers: greptile-apps

Merge Risk: Minimal · up to 4cbbb

Stash restore no longer starts a nested hk process through the post-checkout hook, and a regression test covers it. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a stash restore no longer starts a nested hk through the post-checkout hook. The raw summary says restore_stashed_path sets HK=0 on the git restore command, which matc…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: a stash restore no longer starts a nested hk through the post-checkout hook. The raw summary says restore_stashed_path sets HK=0 on the git restore command, which matches the title. The objectives describe the same intent. The title is specific and uses the conventional fix(scope) format. It is 80 characters, which is slightly long, but the content is accurate.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: jdx/hk
  • Branch: fix/stash-restore-nested-hk
  • File: .coderabbit.yaml
  • Commit: 4cbbbe7
  • Layers: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae8923bd-6f44-4a45-ae9a-320dcc1e7610
Commits

Reviewing files that changed from the base of the PR and between 98dea41 and 4cbbbe7.

Files selected for processing: 2

  • src/git.rs
  • test/stash_restore_no_nested_hk.bats

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

Prevents stash restoration from starting another hk through post-checkout.

  • Stash restores no longer start a nested hk through post-checkout.

No actionable issues found.

Reviews (1) · Last reviewed commit: "fix(stash): stop restoring stashed files..." · Reviewed by Greptile

@jdx
jdx merged commit 512afce into main Nov 18, 2026
31 of 34 checks passed
@jdx
jdx deleted the fix/stash-restore-nested-hk branch November 18, 2026 08:35
@jdx jdx mentioned this pull request Nov 18, 2026
jdx added a commit that referenced this pull request Nov 23, 2026
### 🚀 Features

- **(builtins)** add hk_validate builtin to fail on config warnings by
[@jdx](https://github.com/jdx) in
[#1862](#1862)
- **(builtins)** report ox_lint findings as diagnostics by
[@jdx](https://github.com/jdx) in
[#1871](#1871)
- **(builtins)** add bun_fmt formatter by [@jdx](https://github.com/jdx)
in [#1870](#1870)
- **(builtins)** add scan = "staged" option to betterleaks by
[@jdx](https://github.com/jdx) in
[#1878](#1878)
- **(builtins)** scan every pushed commit for secrets with scan =
"commits" by [@jdx](https://github.com/jdx) in
[#1880](#1880)
- **(step)** add recheck_after_fix to rerun checks a later fix changed
by [@jdx](https://github.com/jdx) in
[#1891](#1891)

### 🐛 Bug Fixes

- **(builtins)** keep empty files empty when fixing with tofu, terraform
and other stdin formatters by [@jdx](https://github.com/jdx) in
[#1874](#1874)
- **(install)** let steps call mise from the global --mise launcher by
[@jdx](https://github.com/jdx) in
[#1875](#1875)
- **(install)** start the per-repo --mise launcher without mise on PATH
by [@jdx](https://github.com/jdx) in
[#1883](#1883)
- **(stash)** stop a nested hk from waiting on the stash lock during
stash recovery by [@jdx](https://github.com/jdx) in
[#1852](#1852)
- **(stash)** stop a stash restore from starting a nested hk through
post-checkout by [@jdx](https://github.com/jdx) in
[#1869](#1869)
- **(stash)** keep intent-to-add files out of the commit with stash =
"none" by [@jdx](https://github.com/jdx) in
[#1884](#1884)
- **(step)** stop adding GIT_WORK_TREE to steps without a dir by
[@jdx](https://github.com/jdx) in
[#1889](#1889)

### 🛡️ Security

- **(deps)** update mise tools by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1854](#1854)
- **(deps)** update dependency jouet to v0.0.4 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1859](#1859)

### 🔍 Other Changes

- **(deps)** update url to 2.5.9 by [@jdx](https://github.com/jdx) in
[#1893](#1893)
- **(entire)** remove trail runners by [@jdx](https://github.com/jdx) in
[8cfa90f](8cfa90f)
- remove the pull_request_target workflows by
[@jdx](https://github.com/jdx) in
[#1876](#1876)

### 📦️ Dependency Updates

- update github actions by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1853](#1853)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1856](#1856)
- update dependency jsdom to v31 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1855](#1855)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1860](#1860)
- ignore unmaintained chrono advisories in cargo-deny by
[@jdx](https://github.com/jdx) in
[#1868](#1868)
- update rust crate pklr to v6.0.4 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1858](#1858)
- update mise tools by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1895](#1895)
- update github actions by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1894](#1894)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1896](#1896)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1899](#1899)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Release-metadata and documentation URL updates only; runtime behavior
changes are documented in the changelog but not introduced in this diff.
> 
> **Overview**
> Cuts **hk v2.14.0** by bumping the crate and CLI version from `2.13.0`
to `2.14.0` in `Cargo.toml`, `Cargo.lock`, `hk.usage.kdl`, and generated
CLI docs, and aligning every docs/example `package://` import with the
new release URL.
> 
> Adds a **2.14.0** section to `CHANGELOG.md` that records what ships in
this tag: new builtins (`hk_validate`, `bun_fmt`, betterleaks `scan =
"staged"` / `"commits"`, ox_lint diagnostics), **`recheck_after_fix`**,
stash/mise/install/step env fixes, dependency and CI housekeeping
(including removing trail runners and `pull_request_target` workflows).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c86fddc. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: mise-en-dev <123107610+mise-en-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant