Skip to content

Comments

fix: stage directive to stage all files matching glob patterns#355

Merged
jdx merged 5 commits intomainfrom
fix-stage-untracked-files
Oct 6, 2025
Merged

fix: stage directive to stage all files matching glob patterns#355
jdx merged 5 commits intomainfrom
fix-stage-untracked-files

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Oct 6, 2025

Summary

  • Fixes staging to include both untracked and unstaged files matching stage glob patterns
  • Simplifies logic by staging ALL files that match the glob, avoiding race conditions
  • Adds comprehensive test coverage for various directory scenarios

Problem

When a step creates new files or modifies existing files, and uses a glob pattern in the stage directive (e.g., stage = "**/owners.yml"), only files in the job set were being staged. Files matching the glob but not in the job set (including newly created untracked files) were not staged.

This was particularly problematic when running from subdirectories, where newly created files would be left unstaged even though they matched the glob pattern.

Solution

  • Modified the candidate selection logic to include ALL files from git status (both untracked_files and unstaged_files) since status is already filtered by the stage pathspecs
  • This ensures any file matching the stage glob pattern gets staged, whether it's:
    • A job file operated on by the step
    • A newly created untracked file
    • A pre-existing unstaged modified file
    • A file in any subdirectory (current, sibling, parent, child)

The fix is simple and avoids race conditions from trying to detect before/after state.

Test Coverage

Added comprehensive test coverage in two files:

test/overstaging_prettier.bats (4 tests):

  1. Stage all matching files including untracked
  2. Do not stage files outside the glob pattern
  3. Stage newly created files by the step
  4. Stage pre-existing unstaged modified files that match

test/stage_from_subdirectory.bats (6 tests):

  1. Stage directive works from subdirectory
  2. Stage directive works from repo root
  3. Stage modified files from subdirectory
  4. Stage files in sibling directories from subdirectory
  5. Stage files in parent and child directories from subdirectory
  6. Do not stage files not matching glob from subdirectory

All 10 tests pass, verifying correct behavior across all scenarios.

Test Plan

  • All new tests pass
  • Existing tests pass (verified with mise run test:bats for the specific files)
  • Full CI passes

🤖 Generated with Claude Code

@jdx jdx changed the title Fix stage directive to include untracked files matching globs fix: stage directive to include untracked files matching globs Oct 6, 2025
When a step creates new files and uses a glob pattern in the `stage`
directive (e.g., `stage = "**/maintainers.yml"`), those newly created
untracked files were not being staged. The staging logic only included
`unstaged_files` in candidates, which doesn't include untracked files.

This fix ensures that for any glob pattern, both unstaged and untracked
files are included as candidates for staging, and the filtering logic
now accepts files that are either unstaged or untracked.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jdx jdx force-pushed the fix-stage-untracked-files branch from 84f6497 to 7c2f745 Compare October 6, 2025 22:41
@jdx jdx enabled auto-merge (squash) October 6, 2025 22:44
jdx and others added 2 commits October 6, 2025 18:35
The fix now stages ALL files (untracked and unstaged) that match the stage
glob patterns, not just newly created ones. This is simpler and avoids race
conditions from trying to detect before/after state.

Updated tests to reflect the correct behavior:
- Files matching the glob are staged (including pre-existing ones)
- Files not matching the glob are not staged (even if created by the step)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Verifies that files created by the step that don't match the stage glob
pattern remain untracked, even when running from a subdirectory.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jdx jdx changed the title fix: stage directive to include untracked files matching globs Fix stage directive to stage all files matching glob patterns Oct 6, 2025
@jdx jdx changed the title Fix stage directive to stage all files matching glob patterns fix: stage directive to stage all files matching glob patterns Oct 6, 2025
@jdx jdx merged commit 9023722 into main Oct 6, 2025
13 of 15 checks passed
@jdx jdx deleted the fix-stage-untracked-files branch October 6, 2025 23:42
@jdx jdx mentioned this pull request Oct 6, 2025
jdx added a commit that referenced this pull request Oct 6, 2025
## [1.18.2](https://github.com/jdx/hk/compare/v1.18.1..v1.18.2) -
2025-10-06

### 🐛 Bug Fixes

- stage directive to include untracked files matching globs by
[@jdx](https://github.com/jdx) in
[#355](#355)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Bumps to v1.18.2 with a bug fix making `stage` include untracked files
matching globs, and updates docs/CLI templates and references to the new
version.
> 
> - **Release 1.18.2**
> - Bug fix: `stage` now includes untracked files matching globs
(`CHANGELOG.md`).
> - **Version bump and references**
> - Update crate/version metadata to `1.18.2` (`Cargo.toml`, CLI
usage/specs).
> - Refresh docs/examples to use `v1.18.2` package URLs (`docs/**`,
`hk-example.pkl`).
> - Update init template and error hint to `v1.18.2` (`src/cli/init.rs`,
`src/config.rs`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
69be2f2. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: mise-en-dev <[email protected]>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 10, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.15.7` -> `1.18.3` |

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.18.3`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1183---2025-10-07)

[Compare Source](jdx/hk@v1.18.2...v1.18.3)

##### 🐛 Bug Fixes

- stash untracked files during partial stashes when HK\_STASH\_UNTRACKED=true by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;357](jdx/hk#357)

### [`v1.18.2`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1182---2025-10-06)

[Compare Source](jdx/hk@v1.18.1...v1.18.2)

##### 🐛 Bug Fixes

- stage directive to include untracked files matching globs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;355](jdx/hk#355)

### [`v1.18.1`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1181---2025-10-05)

[Compare Source](jdx/hk@v1.18.0...v1.18.1)

##### 🐛 Bug Fixes

- prevent race condition when files are deleted between collection and execution by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;353](jdx/hk#353)

### [`v1.18.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1180---2025-10-05)

[Compare Source](jdx/hk@v1.16.0...v1.18.0)

##### 🚀 Features

- add fix-smart-quotes util by [@&#8203;joonas](https://github.com/joonas) in [#&#8203;348](jdx/hk#348)

##### 🐛 Bug Fixes

- add Windows support by guarding Unix-specific file permission APIs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;349](jdx/hk#349)
- handle missing files in update-version script by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;350](jdx/hk#350)
- rewrite update-version script to avoid pipefail issues by [@&#8203;jdx](https://github.com/jdx) in [211b1ac](jdx/hk@211b1ac)
- run render before update-version in release script by [@&#8203;jdx](https://github.com/jdx) in [35d2df3](jdx/hk@35d2df3)
- use \[0-9] instead of \d in ripgrep pattern for better compatibility by [@&#8203;jdx](https://github.com/jdx) in [cf8ebb0](jdx/hk@cf8ebb0)
- explicitly specify search path for ripgrep in update-version script by [@&#8203;jdx](https://github.com/jdx) in [5666f96](jdx/hk@5666f96)

##### 🔍 Other Changes

- add diagnostic output to update-version script by [@&#8203;jdx](https://github.com/jdx) in [aaeea63](jdx/hk@aaeea63)
- add more file existence checks by [@&#8203;jdx](https://github.com/jdx) in [cbace40](jdx/hk@cbace40)
- test rg pattern matching in CI environment by [@&#8203;jdx](https://github.com/jdx) in [a52ea46](jdx/hk@a52ea46)

##### New Contributors

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

### [`v1.16.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1160---2025-10-02)

[Compare Source](jdx/hk@v1.15.7...v1.16.0)

##### 🚀 Features

- add HK\_STAGE setting to control automatic staging of fixed files by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;313](jdx/hk#313)
- suppress check output\_summary when fixer runs with check\_first by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;315](jdx/hk#315)

##### 🐛 Bug Fixes

- \--slow flag now properly enables slow profile by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;317](jdx/hk#317)

##### 📚 Documentation

- Update getting\_started.md by [@&#8203;jdx](https://github.com/jdx) in [a8c1a35](jdx/hk@a8c1a35)

##### 🔍 Other Changes

- Update getting\_started.md by [@&#8203;jdx](https://github.com/jdx) in [58c0564](jdx/hk@58c0564)

</details>

---

### Configuration

📅 **Schedule**: 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 [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzOC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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