-
Notifications
You must be signed in to change notification settings - Fork 732
fix: cursor hooks on windows #11616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: cursor hooks on windows #11616
Conversation
|
@Rettend is attempting to deploy a commit to the GitButler Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a Windows-specific issue where Cursor hooks fail because Cursor sends workspace paths in the format /c:/Users/... instead of the standard C:/Users/.... The leading slash causes GitButler CLI commands to fail with "Failed to access a directory" errors.
Key Changes:
- Added
cursor_path_to_pathbuf()function that detects and strips the leading slash from Windows drive paths in the/c:/format - Updated
handle_after_edit()andhandle_stop()to use the new path conversion function - Added basic unit tests to verify the path transformation behavior
| fn test_cursor_path_to_pathbuf_windows_drive_paths() { | ||
| #[cfg(target_os = "windows")] | ||
| { | ||
| assert_eq!( | ||
| cursor_path_to_pathbuf("/C:/repo").to_string_lossy(), | ||
| "C:/repo" | ||
| ); | ||
| assert_eq!( | ||
| cursor_path_to_pathbuf("/M:/work/repo").to_string_lossy(), | ||
| "M:/work/repo" | ||
| ); | ||
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should also handle edge cases where paths are malformed or have lowercase drive letters. Consider adding test cases for:
- Lowercase drive letters (e.g.,
/c:/repoinstead of/C:/repo) - Edge case where the path is exactly
/C:(length < 3 after stripping prefix) - Paths with backslashes (e.g.,
/C:\repo)
The current byte checking at position 1 would be correct for lowercase drive letters since ASCII 'c' and 'C' both have ':' at position 1 when checking without_leading_slash.as_bytes()[1], but the tests should verify this behavior explicitly.
| fn test_cursor_path_to_pathbuf_windows_drive_paths() { | ||
| #[cfg(target_os = "windows")] | ||
| { | ||
| assert_eq!( | ||
| cursor_path_to_pathbuf("/C:/repo").to_string_lossy(), | ||
| "C:/repo" | ||
| ); | ||
| assert_eq!( | ||
| cursor_path_to_pathbuf("/M:/work/repo").to_string_lossy(), | ||
| "M:/work/repo" | ||
| ); | ||
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should also verify that paths without the problematic format are left unchanged on Windows. For example, regular Windows paths like C:/repo (without the leading slash) should remain as C:/repo, and Unix-style paths like /home/user should remain unchanged. This ensures the function doesn't modify paths unnecessarily.
| { | ||
| if let Some(without_leading_slash) = input.strip_prefix('/') { | ||
| let b = without_leading_slash.as_bytes(); | ||
| if b.len() >= 3 && b[1] == b':' && (b[2] == b'/' || b[2] == b'\\') { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The byte index check uses hardcoded positions (b[1] and b[2]) but doesn't explicitly validate that b[0] is an ASCII alphabetic character representing a drive letter. While the current logic may work in practice since Cursor sends valid drive letters, it would be more robust to check that b[0] is in the range A-Z or a-z. This would prevent false positives for paths like /1:/foo being treated as Windows drive paths.
| if b.len() >= 3 && b[1] == b':' && (b[2] == b'/' || b[2] == b'\\') { | |
| if b.len() >= 3 | |
| && ((b[0] >= b'a' && b[0] <= b'z') || (b[0] >= b'A' && b[0] <= b'Z')) | |
| && b[1] == b':' | |
| && (b[2] == b'/' || b[2] == b'\\') | |
| { |
fix #10665
Cursor sends paths in this format:
/c:/Users, I'm not sure why, but to my knowledge this prevents GitButler from working with Cursor Hooks on Windows.The fix just removes the slash.
I verified that after the fix
but cursor after-editandbut cursor stopare triggered and finish.