diff --git a/bundler/lib/bundler/cli/gem.rb b/bundler/lib/bundler/cli/gem.rb index c9794c40032a..43c3321053b8 100644 --- a/bundler/lib/bundler/cli/gem.rb +++ b/bundler/lib/bundler/cli/gem.rb @@ -192,7 +192,8 @@ def run if use_git Bundler.ui.info "Initializing git repo in #{target}" - `git init #{target}` + require "shellwords" + `git init #{target.to_s.shellescape}` config[:git_default_branch] = File.read("#{target}/.git/HEAD").split("/").last.chomp end diff --git a/bundler/spec/commands/newgem_spec.rb b/bundler/spec/commands/newgem_spec.rb index 01f8a5daea81..4ccf9be6a88d 100644 --- a/bundler/spec/commands/newgem_spec.rb +++ b/bundler/spec/commands/newgem_spec.rb @@ -52,6 +52,17 @@ def bundle_exec_standardrb gem_skeleton_assertions expect(bundled_app("#{gem_name}/.git")).not_to exist end + + context "on a path with spaces" do + before do + Dir.mkdir(bundled_app("path with spaces")) + end + + it "properly initializes git repo", :readline do + bundle "gem #{gem_name}", :dir => bundled_app("path with spaces") + expect(bundled_app("path with spaces/#{gem_name}/.git")).to exist + end + end end shared_examples_for "--mit flag" do