Skip to content

Pass long argument lists to MSYS programs in a response file - #22

Merged
hex2f merged 2 commits into
hex2f:mainfrom
ExpectedArgument:msys-long-args
Nov 7, 2026
Merged

hex2f merged 2 commits into
hex2f:mainfrom
ExpectedArgument:msys-long-args

Conversation

@ExpectedArgument

Copy link
Copy Markdown

Fixes #20.

MSYS programs got their arguments on the Windows command line, which is capped at 32,767 characters, so a long glob such as ls logs/*.out over a few hundred files failed with "The filename or extension is too long" (exit 126). Git Bash hands arguments from one MSYS process to the next without the command line, so it has no such limit.

When the arguments for an MSYS program (run directly, or as a script's interpreter) would make the command line longer than 30,000 bytes, gash now writes them, quoted with msys_quote as before, to a response file and passes @"<file>" instead. The MSYS runtime replaces an @file argument with the file's contents and parses them like the rest of the command line. Before relying on this I checked it with Git's printf.exe started from a native process:

  • A 49 KB file with 1,200 arguments arrived as 1,200 arguments.
  • Double and single quotes, backslashes, a quoted leading @ and * came through as with the command line.
  • @"path with spaces\file" works, but "@file" is taken literally (a quoted @ isn't expanded), so the quote goes after the @.
  • @nosuchfile stays literal.

The file is a delete-on-close temporary (the existing temp_file, now also giving its path, from a new temp_file_named). It stays open until the program has exited. For a background job, which doesn't wait, a thread holds it until the process ends. No file is left behind.

Native programs still get the Windows limit, as they do in Git Bash.

Tests

  • New compat script 073_msys_long_args.sh, with expected output from Git Bash 5.3.15 via regen_expected.ps1. It runs the issue's case (1,200 file names, about 49,000 characters) through ls, cat and a background ls. It also passes a 40,000-character argument to /usr/bin/printf together with arguments holding spaces, quotes, a backslash, a leading @, * and an empty string, and checks that a native program still fails. It fails without the change: ls, cat and the background ls exit 126.
  • cargo test passes: unit tests, 71/71 compat scripts and msys_tmp. No gash-args-* files are left in %TEMP%, and there are no new clippy warnings.

muvahhid kilic and others added 2 commits November 6, 2026 23:11
MSYS programs got their arguments on the Windows command line, which is capped at 32,767 characters, so ls over a few hundred files failed with 'The filename or extension is too long'. Git Bash has no such limit. When the arguments would make the command line longer than 30,000 bytes, write them to a delete-on-close response file and pass @"<file>", which the MSYS runtime expands. The file stays open until the program exits.

Fixes hex2f#20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It sat right after `msys_child`, where hex2f#10 also adds lines, so the two
changes conflicted. Declared a few lines up, they merge in either order.

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

@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. It fixes #20. On main, the new 073 test fails with exit 126. With this branch it matches Git Bash.

I also ran ls over 1,200 file names with accented characters (about 49 KB of arguments). Main fails, and this branch matches Git Bash. No gash-args-* files were left in %TEMP%.

The response file's lifetime looks right to me. For a foreground program it's dropped after wait, and for a background job the thread holds it until the process exits.

The branch is based on an older main, but it merges cleanly with current main and with #23 and #25, and the combined compat suite passes 74/74. The response file goes through the same msys_quote that #25 changes, so the two work together.

@hex2f
hex2f merged commit 23cac99 into hex2f:main Nov 7, 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.

MSYS programs fail with long argument lists (> 32,767 chars) where Git Bash works

2 participants