Commit b6bf1fc
fix: add Windows support by guarding Unix-specific file permission APIs (jdx#349)
## 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
- [x] Compiles successfully on macOS (tested locally)
- [x] 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](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Guards Unix-only permission code for Windows, enables staged rename
detection in git status, and adds tests for renamed files.
>
> - **Compatibility (Windows)**
> - Wrap Unix-specific permission logic with `#[cfg(unix)]` and provide
Windows no-ops in
`src/cli/migrate/pre_commit.rs::make_scripts_executable` and
`src/cli/util/check_executables_have_shebangs.rs`.
> - Gate `PermissionsExt` imports and Unix-specific tests with
`#[cfg(unix)]`; on Windows `is_executable` returns `false`.
> - **Git status improvements**
> - Enable rename detection with libgit2 via
`status_options.renames_head_to_index(true)` and shell fallback by
removing `--no-renames` from `git status --porcelain`.
> - **Tests**
> - Add `test/staged_renamed_files.bats` to assert
`git.staged_renamed_files` detection (single and multiple renames).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9a7c15e. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude <[email protected]>1 parent 25a4b15 commit b6bf1fc
File tree
2 files changed
+52
-29
lines changed- src/cli
- migrate
- util
2 files changed
+52
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1704 | 1704 | | |
1705 | 1705 | | |
1706 | 1706 | | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
1727 | 1710 | | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
| 1711 | + | |
| 1712 | + | |
1732 | 1713 | | |
1733 | 1714 | | |
1734 | 1715 | | |
1735 | 1716 | | |
1736 | | - | |
| 1717 | + | |
| 1718 | + | |
1737 | 1719 | | |
1738 | 1720 | | |
1739 | | - | |
| 1721 | + | |
1740 | 1722 | | |
1741 | 1723 | | |
1742 | 1724 | | |
1743 | 1725 | | |
1744 | 1726 | | |
1745 | 1727 | | |
1746 | 1728 | | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
1747 | 1757 | | |
1748 | 1758 | | |
1749 | 1759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | | - | |
43 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
| |||
100 | 111 | | |
101 | 112 | | |
102 | 113 | | |
| 114 | + | |
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
| |||
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| 129 | + | |
117 | 130 | | |
118 | 131 | | |
119 | 132 | | |
| |||
0 commit comments