Initialize the new gem's git repo without a subshell#9670
Merged
Conversation
`bundle gem` ran `git init` through a backtick subshell with POSIX shell quoting. On Windows the backtick invokes cmd.exe, which ignores the POSIX escaping, so a target path containing spaces was split and the repo was created in the wrong place. Spawn git directly with an argument array, matching the `git add` call below. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates bundle gem to initialize a new gem’s git repository without invoking a shell, fixing Windows failures when the target path contains spaces. It also reenables a previously skipped Windows spec that verifies git initialization in a spaced path.
Changes:
- Replace backtick-based
git init(with POSIX shell escaping) with a direct process spawn viaIO.popenusing an argument array. - Remove the Windows-only skip for the “path with spaces” git initialization spec now that the underlying issue is fixed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| spec/commands/newgem_spec.rb | Removes a Windows skip so the “path with spaces” git init behavior is exercised on Windows again. |
| lib/bundler/cli/gem.rb | Switches git init to a direct spawn (IO.popen argv) to avoid shell quoting issues on Windows paths with spaces. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Initialize the new gem's git repo without a subshell (cherry picked from commit 3d3e02d)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Initialize the new gem's git repo without a subshell (cherry picked from commit 3d3e02d)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Initialize the new gem's git repo without a subshell (cherry picked from commit 3d3e02d)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Initialize the new gem's git repo without a subshell (cherry picked from commit 3d3e02d)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bundle geminitialized the new gem's git repository by runninggit initthrough a backtick subshell with POSIX shell quoting applied to the target path. On Windows the backtick invokes cmd.exe, which does not honor the POSIX escaping, so a path containing spaces was split and the repository ended up in the wrong location. The following read of.git/HEADthen failed. Spawning git directly with an argument array avoids the shell entirely, needs no quoting, and matches thegit addinvocation a few lines below.The newgem spec covering git initialization on a path with spaces was skipped on Windows for this reason. It runs and passes now, so the skip is removed.
Forward port of ruby/ruby#17599.