Skip to content

Fix Windows path quoting in shell templates#161

Merged
max-sixty merged 8 commits intomainfrom
ci
Dec 11, 2025
Merged

Fix Windows path quoting in shell templates#161
max-sixty merged 8 commits intomainfrom
ci

Conversation

@max-sixty
Copy link
Owner

Summary

  • Fix root cause of Windows path quoting issue in shell templates
  • Convert Windows native paths (D:\...) to POSIX format (/d/...) for Git Bash compatibility
  • Enable 15+ tests that were previously skipped due to path differences

Root Cause

When Git Bash executes commands, it sets MSYSTEM environment variable. The shell_escape::escape() function detects this and uses unix escaping. However, Windows paths contain : and \ characters which are NOT in the unix safe character set, causing them to be wrapped in single quotes.

This caused snapshot mismatches between Windows and Unix because:

  • Unix: /tmp/test/repo → no escaping needed (all safe chars)
  • Windows: D:\a\worktrunk\repo → gets quoted as 'D:\a\worktrunk\repo'

Solution

Convert Windows paths to POSIX format (/d/a/worktrunk/repo) in build_hook_context() before template expansion. This ensures:

  1. Paths work correctly with Git Bash (which understands POSIX paths)
  2. Paths don't trigger shell escaping (forward slashes are in the safe char set)
  3. Snapshots match between platforms

🤖 Generated with Claude Code

max-sixty and others added 5 commits December 11, 2025 13:41
Now that we've verified echo commands work through Git Bash on Windows,
enable all tests that use shell commands like 'echo ... > file.txt'.

Remaining 19 Windows-ignored tests have actual platform incompatibilities:
- chmod command (Unix only)
- File locking during worktree removal
- git status CRLF/LF differences
- /tmp paths
- cat command

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

Co-Authored-By: Claude <noreply@anthropic.com>
Selectively enable tests that use:
- Simple echo commands without path template variables
- Non-path template variables ({{ branch }}, {{ target }}, {{ default_branch }})

Tests using path template variables ({{ worktree }}, {{ main_worktree }},
{{ repo_root }}, {{ worktree_name }}) remain ignored due to shell quoting
differences when these paths are echoed on Windows via Git Bash.

Enabled tests by file:
- approval_ui.rs: 7 tests
- merge.rs: 3 tests
- switch.rs: 2 tests
- user_hooks.rs: 2 tests
- remove.rs: 1 test
- post_start_commands.rs: 1 test

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

Co-Authored-By: Claude <noreply@anthropic.com>
Convert Windows native paths (D:\...) to POSIX format (/d/...)
in hook context variables. This avoids shell escaping of `:` and `\`
characters that caused snapshot mismatches between Windows and Unix.

The root cause was that shell_escape::escape() uses unix escaping
when MSYSTEM is set (as it is in Git Bash), and Windows paths contain
characters not in the unix safe character set, causing them to be
wrapped in single quotes.

Changes:
- Add to_posix_path() helper for Git Bash compatibility
- Update build_hook_context() to use POSIX paths for worktree/repo_root
- Enable 15+ tests that were previously skipped due to path differences

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

Co-Authored-By: Claude <noreply@anthropic.com>
The to_posix_path() conversion in command_executor.rs converts Windows
paths like C:\Users\...\repo to POSIX format /c/Users/.../repo for Git
Bash compatibility. However, snapshot redaction patterns weren't catching
these POSIX-formatted paths.

Add:
- to_posix_path() helper in test common module
- POSIX path filters for repo and worktree paths
- Regex fallback pattern for POSIX-style Windows temp paths

This ensures template variables like ${worktree} and ${repo_root} are
properly redacted in snapshots regardless of path format.

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

Co-Authored-By: Claude <noreply@anthropic.com>
max-sixty and others added 3 commits December 11, 2025 13:46
Instead of hand-rolling POSIX path conversion, use cygpath from Git for
Windows which handles all edge cases (UNC paths, verbatim paths, etc.).

- Derive cygpath location from cached ShellConfig (no duplicate Git-finding)
- Fall back to pass-through if cygpath unavailable
- Remove duplicate to_posix_path implementations from command_executor and tests

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

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit a87c8a3 into main Dec 11, 2025
18 checks passed
@max-sixty max-sixty deleted the ci branch December 11, 2025 23:29
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