Skip to content

Initialize the new gem's git repo without a subshell#9670

Merged
hsbt merged 1 commit into
masterfrom
claude/pensive-swartz-489c46
Jul 2, 2026
Merged

Initialize the new gem's git repo without a subshell#9670
hsbt merged 1 commit into
masterfrom
claude/pensive-swartz-489c46

Conversation

@hsbt

@hsbt hsbt commented Jul 2, 2026

Copy link
Copy Markdown
Member

bundle gem initialized the new gem's git repository by running git init through 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/HEAD then failed. Spawning git directly with an argument array avoids the shell entirely, needs no quoting, and matches the git add invocation 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.

`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>
Copilot AI review requested due to automatic review settings July 2, 2026 02:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 via IO.popen using 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 hsbt merged commit 3d3e02d into master Jul 2, 2026
111 checks passed
@hsbt hsbt deleted the claude/pensive-swartz-489c46 branch July 2, 2026 06:24
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants