Skip to content

Comments

fix: add Windows support by guarding Unix-specific file permission APIs#349

Merged
jdx merged 7 commits intomainfrom
fix-windows-build
Oct 5, 2025
Merged

fix: add Windows support by guarding Unix-specific file permission APIs#349
jdx merged 7 commits intomainfrom
fix-windows-build

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Oct 5, 2025

Summary

The v1.17.0 release workflow failed on Windows builds because Unix-specific file permission APIs were used without platform guards.

Problem

The Windows build was failing with errors like:

error[E0433]: failed to resolve: could not find `unix` in `os`

This occurred in two files:

  • src/cli/migrate/pre_commit.rs:1707 - use std::os::unix::fs::PermissionsExt
  • src/cli/util/check_executables_have_shebangs.rs:3 - use std::os::unix::fs::PermissionsExt

Solution

Added proper #[cfg(unix)] guards around all Unix-specific code:

  1. check_executables_have_shebangs.rs:

    • Guarded PermissionsExt import with #[cfg(unix)]
    • Split is_executable() implementation: Unix checks execute bits, Windows returns false
    • Marked Unix-specific tests with #[cfg(unix)]
  2. pre_commit.rs:

    • Wrapped entire make_scripts_executable() Unix implementation in #[cfg(unix)] block
    • Added Windows no-op implementation (Windows uses file associations, not execute bits)

Behavior

  • Unix/Linux/macOS: No change in behavior - still checks/sets execute permissions
  • Windows: Functions compile and run but don't check/set Unix permissions (which don't exist on Windows)

Test Plan

  • Compiles successfully on macOS (tested locally)
  • Will verify Windows builds pass in CI

Fixes the Windows build failures in https://github.com/jdx/hk/actions/runs/18261671379

🤖 Generated with Claude Code


Note

Adds platform guards around Unix-specific file permission code; provides no-op/false paths on Windows and gates related tests.

  • Platform guards for Unix-specific permissions
    • src/cli/migrate/pre_commit.rs
      • Wrap make_scripts_executable() implementation in #[cfg(unix)]; add #[cfg(not(unix))] no-op.
      • Ensure execute bits set for *.py and *.sh in vendor root; retain pre_commit_hooks handling for Python files.
    • src/cli/util/check_executables_have_shebangs.rs
      • Guard PermissionsExt import and is_executable() logic with #[cfg(unix)]; on Windows is_executable() returns false.
      • Mark Unix-only tests with #[cfg(unix)].

Written by Cursor Bugbot for commit d184907. This will update automatically on new commits. Configure here.

jdx and others added 6 commits October 5, 2025 10:08
…able

Swift was added as an experimental tool to support vendoring language:
swift hooks in pre-commit migration. However, it adds significant CI
setup time and complexity.

Changes:
- Remove swift from mise.toml tools
- Remove experimental = true setting (no longer needed)
- Add skip condition to swift vendoring test when swift unavailable
- Swift vendoring will still work if users have swift installed locally

The migrate pre-commit functionality for swift hooks remains intact,
it just won't be tested in CI unless swift happens to be available.

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

Co-Authored-By: Claude <[email protected]>
This fixes a bug where staged_renamed_files was always empty because:
1. The shell git path used --no-renames flag
2. The libgit2 path didn't enable rename detection

Changes:
- Removed --no-renames flag from git status command
- Added renames_head_to_index(true) to libgit2 StatusOptions
- Added comprehensive bats tests for staged_renamed_files detection

This ensures that conditions like `git.staged_renamed_files != []`
work correctly in both libgit2 and shell git modes.

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

Co-Authored-By: Claude <[email protected]>
- libgit2: Use renames_index_to_workdir(true) to detect renames between index and workdir
- shell git: Use git add -N + git diff --find-renames trick to detect unstaged renames
- Add comprehensive tests for unstaged rename detection
- Change st == git2::Status::WT_RENAMED to st.is_wt_renamed() for consistency
The Windows build was failing because we were using Unix-specific APIs
(`std::os::unix::fs::PermissionsExt`) without platform guards.

Changes:
- Added #[cfg(unix)] guards around all uses of PermissionsExt
- Provided Windows fallback implementations that no-op appropriately
- Marked Unix-specific tests with #[cfg(unix)]

On Windows:
- `is_executable()` returns false since Windows doesn't use Unix execute bits
- `make_scripts_executable()` no-ops since Windows uses file associations

Fixes the Windows build failures in the v1.17.0 release workflow.

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

Co-Authored-By: Claude <[email protected]>
@jdx jdx enabled auto-merge (squash) October 5, 2025 17:27
@jdx jdx merged commit b6bf1fc into main Oct 5, 2025
12 checks passed
@jdx jdx deleted the fix-windows-build branch October 5, 2025 17:31
jdx added a commit that referenced this pull request Oct 5, 2025
## Summary
Fixes the release-plz workflow failure by handling the case where
ripgrep finds no matching files.

## Problem
The `update-version.sh` script was failing with:
```
sed: no input files
```

This happened when `rg` didn't find any matching package:// URLs in the
repository. When `rg` returns no results, `xargs` would still try to run
`sed` with no input, causing it to fail.

This blocked the release workflow:
https://github.com/jdx/hk/actions/runs/18262051312/job/51991277623

## Solution
Added the `-r` (or `--no-run-if-empty`) flag to `xargs`, which prevents
it from running the command when there's no input from stdin.

This is a standard practice for pipelines where the input may be empty:
```bash
# Before (fails if rg finds nothing):
rg pattern --files-with-matches -0 | xargs -0 sed ...

# After (succeeds even if rg finds nothing):
rg pattern --files-with-matches -0 | xargs -0 -r sed ...
```

## Behavior
- **When files match**: Works exactly as before - updates version
strings
- **When no files match**: Exits successfully without running sed (no
error)

## Test Plan
- [x] Tested locally with pattern that matches no files
- [x] Tested locally with pattern that matches files
- [x] Will verify release-plz workflow succeeds in CI

Related to #349 (Windows build fix)

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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Add -r to xargs in update-version.sh so sed isn't run when rg finds no
matches, avoiding failures.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
76f7ba8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude <[email protected]>
@jdx jdx mentioned this pull request Oct 5, 2025
jdx added a commit that referenced this pull request Oct 5, 2025
## [1.18.0](https://github.com/jdx/hk/compare/v1.17.0..v1.18.0) -
2025-10-05

### 🚀 Features

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

### 🐛 Bug Fixes

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

### 🔍 Other Changes

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

### New Contributors

- @joonas made their first contribution in
[#348](#348)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Bumps hk to 1.18.0, updates docs/CLI/templates to new Pkl package
URLs, and refreshes a dependency.
> 
> - **Version bump**:
> - Set crate/app version to `1.18.0` in `Cargo.toml`, `Cargo.lock`
(package `hk`), `hk.usage.kdl`, `docs/cli/commands.json`, and
`docs/cli/index.md`.
> - **Docs/examples**:
> - Update `amends`/`import` URLs from `v1.2.0` to `v1.18.0` across
`docs/*`, `hk-example.pkl`, and example `.pkl` files.
>   - Add `CHANGELOG.md` entry for `1.18.0`.
> - **CLI/templates**:
>   - Update init template in `src/cli/init.rs` to use `v1.18.0` URLs.
>   - Refresh error hint URL in `src/config.rs` to `v1.18.0`.
> - **Dependencies**:
>   - Bump `flate2` to `1.1.4` in `Cargo.lock`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
fc59481. 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