Skip to content

Pass //-escaped switches to native programs with one slash, as MSYS does - #11

Merged
hex2f merged 2 commits into
hex2f:mainfrom
ExpectedArgument:msys-double-slash-switches
Nov 6, 2026
Merged

hex2f merged 2 commits into
hex2f:mainfrom
ExpectedArgument:msys-double-slash-switches

Conversation

@ExpectedArgument

Copy link
Copy Markdown

Found by running the same commands through Git Bash and gash side by side.

MSYS strips one slash from an argument that starts with // before passing it to a native program. That is how Windows switches get through path conversion: cmd //c echo hi, taskkill //F //PID 123, schtasks //query. gash passed them on unchanged, so cmd //c echo hi started an interactive cmd instead of running the command.

convert_arg now does what Git Bash does: //c → /c, //F → /F, ///x → //x and // → /, while UNC-like arguments (//server/share/x, //c/x) are left alone. As before, nothing is converted when MSYS_NO_PATHCONV is set.

Tests

  • New compat script 067_double_slash_switches.sh, with expected output from Git Bash 5.3.15 via regen_expected.ps1. It fails without the change and passes with it.
  • cargo test passes: unit tests, 62/62 compat scripts and msys_tmp.

MSYS strips one slash from an argument that starts with // before
passing it to a native program, which is how Windows switches survive
path conversion (cmd //c, taskkill //F). gash passed them on unchanged,
so cmd //c echo hi started an interactive cmd. convert_arg now matches
Git Bash: //c becomes /c and ///x becomes //x, while UNC-like arguments
such as //server/share are left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ExpectedArgument
ExpectedArgument force-pushed the msys-double-slash-switches branch from 582a313 to a13c18d Compare November 6, 2026 19:26

@hex2f hex2f left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The conversion matches Git Bash. One thing about the test, line comment below.

I merged it onto current main. When MSYS_NO_PATHCONV isn't set, the new script matches the Git Bash output and the rest of the suite passes.

@@ -0,0 +1,7 @@
# An argument starting with // is an escaped Windows switch: a native program gets it with one
# slash fewer, as with MSYS (`cmd //c`, `taskkill //F`), unless it looks like `//server/share`.
git rev-parse --sq-quote //c //F ///x //server/share/x //c/x //

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test isn't hermetic. If MSYS_NO_PATHCONV=1 is already exported when the suite runs, this line gets no conversion and the script fails. Claude Code exports it, and some Git for Windows setups do too. With the variable unset, it passes. Suggestion: start the script with unset MSYS_NO_PATHCONV MSYS2_ARG_CONV_EXCL. Or, to fix this for every script, add both names to REMOVED_ENV in tests/compat.rs and to regen_expected.ps1.

In that state, cmd //c echo on line 4 also starts an interactive cmd, because //c reaches it unconverted.

The script expected conversion on, so it failed when MSYS_NO_PATHCONV or MSYS2_ARG_CONV_EXCL was already exported, as Claude Code does, and cmd //c then started an interactive cmd. It now unsets both first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ExpectedArgument

Copy link
Copy Markdown
Author

Thanks! Fixed: the script now starts with unset MSYS_NO_PATHCONV MSYS2_ARG_CONV_EXCL. With MSYS_NO_PATHCONV=1 and MSYS2_ARG_CONV_EXCL=* exported, cargo test passes (62/62 compat scripts on this branch), and so it does with them unset. Git Bash gives the same expected output in both cases.

@hex2f

hex2f commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thanks, that fixes it. I merged b4e1fc3 onto current main and it merges cleanly. With MSYS_NO_PATHCONV=1 still exported, cargo test passes 71/71. Together with #10 and #21 it passes 72/72, with the conversion variables exported, unset, and with MSYS2_ARG_CONV_EXCL=*. No new clippy warnings. Looks good to merge.

@hex2f
hex2f merged commit 55cfc04 into hex2f:main Nov 6, 2026
1 check passed
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.

2 participants