Skip to content

fix(git): skip untracked scan when HK_STASH_UNTRACKED=false#861

Merged
jdx merged 1 commit intomainfrom
fix/git-status-skip-untracked-when-disabled
Apr 23, 2026
Merged

fix(git): skip untracked scan when HK_STASH_UNTRACKED=false#861
jdx merged 1 commit intomainfrom
fix/git-status-skip-untracked-when-disabled

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Apr 23, 2026

Summary

  • When GIT_WORK_TREE points at a large directory (e.g. a YADM dotfile repo where the worktree is $HOME), the unconditional git status --untracked-files=all scan takes tens of seconds and emits hundreds of megabytes of output on every hk invocation.
  • HK_STASH_UNTRACKED=false previously had no effect on the status scan — it only suppressed stashing. This change honors it in Git::status() (and the internal stash porcelain parse, which already ignores untracked entries) so users of large worktrees can opt out of the scan entirely. Both the libgit2 and shell-git paths are updated.
  • Fixes #860.

Test plan

  • mise run test:bats test/bare_repo_env_vars.bats (7 tests × 2 modes)
  • mise run test:bats test/stash_untracked_with_partial_stash.bats, test/stash_preservation_on_error.bats, test/pre_commit_does_not_stash_staged_only_files.bats, test/git_status_ad_deleted.bats, test/cargo_fmt_does_not_stage_manifest.bats
  • mise run test:cargo (145 passed)
  • New regression test: HK_STASH_UNTRACKED=false skips untracked scan in large worktree (#860)

🤖 Generated with Claude Code


Note

Medium Risk
Changes how Git::status() (libgit2 and shell-git paths) and stash detection call git status, which can affect which files hk considers (especially untracked files) and therefore which steps run. The behavior is gated behind HK_STASH_UNTRACKED=false, but it touches core git/file-detection logic.

Overview
Honors HK_STASH_UNTRACKED=false by skipping untracked-file enumeration during status collection (using --untracked-files=no for shell git and disabling untracked options for libgit2) to avoid expensive scans when GIT_WORK_TREE is very large.

Updates the stash porcelain parse to likewise avoid untracked scanning when untracked stashing is disabled, documents the new behavior in docs/environment_variables.md, and adds a Bats regression test ensuring untracked “junk” in a large worktree doesn’t appear in hk check --all output.

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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 23, 2026

Greptile Summary

This PR makes HK_STASH_UNTRACKED=false actually suppress the underlying git status --untracked-files=all scan, fixing a serious performance regression for large GIT_WORK_TREE directories (e.g. YADM dotfile repos where the worktree is $HOME). Both the libgit2 path (StatusOptions::include_untracked / recurse_untracked_dirs) and the shell-git path (the --untracked-files=… flag) are updated in Git::status(), and the stash porcelain parse in section 3 is updated for consistency. Documentation is updated to document the new side-effect of the flag.

Confidence Score: 5/5

Safe to merge — the logic change is correct in both code paths, preserves existing behaviour when the env var is not set, and is documented.

The only open concern (regression-test assertion quality) was already raised in a prior review thread; no new P0/P1 issues are present. The Rust change is minimal, well-contained, and correctly honours the existing HK_STASH_UNTRACKED semantics in all four affected code sites.

No files require special attention beyond the already-discussed test assertion in test/bare_repo_env_vars.bats.

Important Files Changed

Filename Overview
src/git.rs Reads HK_STASH_UNTRACKED once per status() call and threads it through both the libgit2 and shell-git code paths; also propagates it to the stash porcelain parse in section 3 — logic is correct and complete.
docs/environment_variables.md Adds a clear explanation of the new HK_STASH_UNTRACKED=false scan-skipping behavior, including the YADM / large-GIT_WORK_TREE motivation — accurate and useful.
test/bare_repo_env_vars.bats Regression test for #860 exercises the code path correctly but the refute_output assertion (already flagged in a prior review thread) may pass even without the fix since untracked filenames are not normally included in hk check --all output.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Git::status() called"] --> B["read *env::HK_STASH_UNTRACKED\n→ include_untracked: bool"]
    B --> C{libgit2 repo\navailable?}
    C -- yes --> D["status_options.include_untracked(include_untracked)\nstatus_options.recurse_untracked_dirs(include_untracked)"]
    D --> E["run libgit2 staged scan\nrun libgit2 workdir scan\n(untracked entries absent when false)"]
    C -- no --> F{include_untracked?}
    F -- true --> G["--untracked-files=all"]
    F -- false --> H["--untracked-files=no"]
    G & H --> I["git status --porcelain FLAG -z"]
    E & I --> J["return GitStatus\n(untracked_files empty when false)"]
    J --> K["stash porcelain parse (§3)\nsame FLAG applied"]
Loading

Reviews (2): Last reviewed commit: "fix(git): skip untracked scan when HK_ST..." | Re-trigger Greptile

Comment thread test/bare_repo_env_vars.bats
When `GIT_WORK_TREE` points at a very large directory (e.g. a YADM
dotfile repo where the worktree is `$HOME`), the unconditional
`git status --untracked-files=all` scan takes tens of seconds and
produces hundreds of megabytes of output on every hk invocation.

The `HK_STASH_UNTRACKED=false` env var previously had no effect on the
status scan itself — it only suppressed stashing. Honor it in
`Git::status()` (and the internal stash porcelain parse, which already
ignores untracked entries) so that users of large worktrees can opt out
of the scan entirely. Both the libgit2 and shell-git paths are updated.

Closes #860

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jdx jdx force-pushed the fix/git-status-skip-untracked-when-disabled branch from 5fe8fdf to 4049f37 Compare April 23, 2026 20:48
@jdx jdx enabled auto-merge (squash) April 23, 2026 20:56
@jdx jdx merged commit dcc9e64 into main Apr 23, 2026
20 checks passed
@jdx jdx deleted the fix/git-status-skip-untracked-when-disabled branch April 23, 2026 20:58
@jdx jdx mentioned this pull request Apr 23, 2026
jdx added a commit that referenced this pull request Apr 24, 2026
### 🐛 Bug Fixes

- **(git)** skip untracked scan when HK_STASH_UNTRACKED=false by
[@jdx](https://github.com/jdx) in
[#861](#861)
- **(run)** add post-commit and pre-rebase subcommands by
[@jdx](https://github.com/jdx) in
[#858](#858)

### 📚 Documentation

- **(install)** recommend global hooks as primary setup path by
[@jdx](https://github.com/jdx) in
[#855](#855)
- add cross-site announcement banner by [@jdx](https://github.com/jdx)
in [#857](#857)
- respect banner expires field by [@jdx](https://github.com/jdx) in
[#862](#862)

### 🔍 Other Changes

- vendor bats test helpers instead of git submodules by
[@jdx](https://github.com/jdx) in
[#859](#859)

### 📦️ Dependency Updates

- bump communique to 1.0.3 by [@jdx](https://github.com/jdx) in
[#863](#863)
- update anthropics/claude-code-action digest to e58dfa5 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#864](#864)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk release bookkeeping only: version numbers, generated
CLI/docs, and lockfile dependency bumps with no runtime logic changes.
> 
> **Overview**
> **Release prep for `v1.44.1`.** Updates `Cargo.toml`/`Cargo.lock`
(including `libc`) and all version references in generated CLI docs
(`docs/cli/*`, `hk.usage.kdl`).
> 
> Refreshes documentation examples to reference the new `v1.44.1` Pkl
package URLs and adds the `1.44.1` entry to `CHANGELOG.md`.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d7637d4. 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>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 8, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.43.0` → `1.45.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/hk (hk)</summary>

### [`v1.45.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1450---2026-05-04)

[Compare Source](jdx/hk@v1.44.3...v1.45.0)

##### 🚀 Features

- **(builtins)** add `buildifier` format and lint built-ins by [@&#8203;plx](https://github.com/plx) in [#&#8203;896](jdx/hk#896)

##### 🐛 Bug Fixes

- **(step)** only auto-batch when rendered command exceeds ARG\_MAX by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;901](jdx/hk#901)

##### 📚 Documentation

- thank Namespace for GitHub Actions runner support by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;895](jdx/hk#895)

##### 🔍 Other Changes

- **(ci)** use !cancelled() instead of always() for final job by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;906](jdx/hk#906)
- **(docs)** remove shrill.en.dev analytics script by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;903](jdx/hk#903)
- remove rust-cache from release jobs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;893](jdx/hk#893)
- invert CLAUDE.md/AGENTS.md so AGENTS.md is canonical by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;905](jdx/hk#905)
- set dev profile debug to 1 by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;907](jdx/hk#907)

##### 📦️ Dependency Updates

- update anthropics/claude-code-action digest to [`fefa07e`](jdx/hk@fefa07e) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;897](jdx/hk#897)
- update jdx/mise-action digest to [`1648a78`](jdx/hk@1648a78) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;898](jdx/hk#898)
- update apple-actions/import-codesign-certs action to v7 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;900](jdx/hk#900)
- update autofix-ci/action action to v1.3.4 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;899](jdx/hk#899)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;908](jdx/hk#908)

##### New Contributors

- [@&#8203;plx](https://github.com/plx) made their first contribution in [#&#8203;896](jdx/hk#896)

### [`v1.44.3`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1443---2026-04-30)

[Compare Source](jdx/hk@v1.44.2...v1.44.3)

##### 🐛 Bug Fixes

- **(hook)** do not stage fixes when fail\_on\_fix=true by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;892](jdx/hk#892)
- use site domain for plausible data-domain by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;886](jdx/hk#886)
- make text-mode progress output usable in CI by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;890](jdx/hk#890)

##### 📚 Documentation

- prefix GitHub star count with ★ glyph by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;883](jdx/hk#883)

##### 🔍 Other Changes

- **(release)** dedupe sponsor section in release notes by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;881](jdx/hk#881)
- switch analytics from gtm/goatcounter to plausible by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;885](jdx/hk#885)
- migrate to namespace.so runners by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;891](jdx/hk#891)

### [`v1.44.2`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1442---2026-04-26)

[Compare Source](jdx/hk@v1.44.1...v1.44.2)

##### 🐛 Bug Fixes

- **(builtins)** silence pklr deprecation warnings on Builtins.pkl load by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;880](jdx/hk#880)
- **(ci)** serialize docs lint step by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;874](jdx/hk#874)
- **(config)** include main pkl path in cache fresh files by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;879](jdx/hk#879)
- **(docs)** stack banner message and link on mobile by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;865](jdx/hk#865)
- **(docs)** pin banner close button to top-right corner on mobile by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;867](jdx/hk#867)

##### 📚 Documentation

- **(site)** show release version and github stars by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;872](jdx/hk#872)

##### 🔍 Other Changes

- add pr-closer workflow by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;876](jdx/hk#876)

##### 📦️ Dependency Updates

- bump communique 1.0.3 → 1.0.4 by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;868](jdx/hk#868)
- update anthropics/claude-code-action digest to [`2da6cfa`](jdx/hk@2da6cfa) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;869](jdx/hk#869)
- update anthropics/claude-code-action digest to [`567fe95`](jdx/hk@567fe95) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;870](jdx/hk#870)
- bump communique to 1.1.2 by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;875](jdx/hk#875)

### [`v1.44.1`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1441---2026-04-24)

[Compare Source](jdx/hk@v1.44.0...v1.44.1)

##### 🐛 Bug Fixes

- **(git)** skip untracked scan when HK\_STASH\_UNTRACKED=false by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;861](jdx/hk#861)
- **(run)** add post-commit and pre-rebase subcommands by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;858](jdx/hk#858)

##### 📚 Documentation

- **(install)** recommend global hooks as primary setup path by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;855](jdx/hk#855)
- add cross-site announcement banner by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;857](jdx/hk#857)
- respect banner expires field by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;862](jdx/hk#862)

##### 🔍 Other Changes

- vendor bats test helpers instead of git submodules by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;859](jdx/hk#859)

##### 📦️ Dependency Updates

- bump communique to 1.0.3 by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;863](jdx/hk#863)
- update anthropics/claude-code-action digest to [`e58dfa5`](jdx/hk@e58dfa5) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;864](jdx/hk#864)

### [`v1.44.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1440---2026-04-23)

[Compare Source](jdx/hk@v1.43.0...v1.44.0)

##### 🚀 Features

- **(check)** implement --plan, --why, and --json by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;848](jdx/hk#848)
- **(cocogitto)** add cocogitto conventional commits config to hk builtin config by [@&#8203;hituzi-no-sippo](https://github.com/hituzi-no-sippo) in [#&#8203;838](jdx/hk#838)
- **(git)** support GIT\_DIR/GIT\_WORK\_TREE for bare-repo dotfile managers by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;847](jdx/hk#847)
- **(install)** use Git 2.54 config-based hooks with --global support by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;853](jdx/hk#853)

##### 🐛 Bug Fixes

- use text progress in CI by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;845](jdx/hk#845)

##### 📚 Documentation

- generalize agent guidelines by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;846](jdx/hk#846)
- add releases nav and aube lock by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;849](jdx/hk#849)

##### 🔍 Other Changes

- **(release)** append en.dev sponsor blurb to release notes by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;854](jdx/hk#854)
- bump communique to 1.0.1 by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;850](jdx/hk#850)

##### 📦️ Dependency Updates

- update actions-rust-lang/setup-rust-toolchain digest to [`2b1f5e9`](jdx/hk@2b1f5e9) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;832](jdx/hk#832)
- update anthropics/claude-code-action digest to [`c3d45e8`](jdx/hk@c3d45e8) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;833](jdx/hk#833)
- update rust crate tokio to v1.52.1 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;834](jdx/hk#834)
- update actions/upload-pages-artifact action to v5 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;835](jdx/hk#835)
- update taiki-e/upload-rust-binary-action digest to [`f0d45ae`](jdx/hk@f0d45ae) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;839](jdx/hk#839)
- update rust crate clx to v2 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;836](jdx/hk#836)
- update anthropics/claude-code-action digest to [`0d2971c`](jdx/hk@0d2971c) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;841](jdx/hk#841)
- update anthropics/claude-code-action digest to [`38ec876`](jdx/hk@38ec876) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;842](jdx/hk#842)
- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;851](jdx/hk#851)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNjguNSIsInVwZGF0ZWRJblZlciI6IjQzLjE2OC41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
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