diff options
author | The Bundler Bot <bot@bundler.io> | 2017-03-23 08:14:55 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-03-23 08:14:55 +0000 |
commit | 5c29724cea208aaa25b8b6af9f2764f678768032 (patch) | |
tree | 0e1db72f2771821154f927136dc1d22c7c3bb62f | |
parent | c231df4add0177dcb5dff1abd816a69b1b993792 (diff) | |
parent | 1adf3a87dee737e01c14e18161f4b7681176d9d7 (diff) | |
download | bundler-5c29724cea208aaa25b8b6af9f2764f678768032.tar.gz |
Auto merge of #5524 - colby-swandale:fix-gem-command-git, r=colby-swandale
Fix `bundle gem` command without having git
So the `gem` command is still breaking on master if `git` is not installed on the machine. This is because we're not checking if git is installed before we init a new git repo.
The test for #5466 is also not actually testing if git is not installed, it's only removing the git config which we already have tests for as well.
@segiddins Do you know a way i can stub `Bundler.git_present?` in the sub-process or have `git` appear to not be present in rspec?
-rw-r--r-- | lib/bundler/cli/gem.rb | 13 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 40 |
2 files changed, 35 insertions, 18 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 3d746f50d6..7fa005289e 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -54,7 +54,6 @@ module Bundler templates = { "Gemfile.tt" => "Gemfile", - "gitignore.tt" => ".gitignore", "lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb", "lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb", "newgem.gemspec.tt" => "#{name}.gemspec", @@ -69,6 +68,8 @@ module Bundler bin/setup ) + templates.merge!("gitignore.tt" => ".gitignore") if Bundler.git_present? + if test_framework = ask_and_set_test_framework config[:test] = test_framework config[:test_framework_version] = TEST_FRAMEWORK_VERSIONS[test_framework] @@ -137,10 +138,12 @@ module Bundler path.chmod(executable) end - Bundler.ui.info "Initializing git repo in #{target}" - Dir.chdir(target) do - `git init` - `git add .` + if Bundler.git_present? + Bundler.ui.info "Initializing git repo in #{target}" + Dir.chdir(target) do + `git init` + `git add .` + end end # Open gemspec in editor diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 43063b734d..6ce19124f5 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -158,22 +158,36 @@ RSpec.describe "bundle gem" do expect(bundled_app("test_gem/README.md").read).not_to include("github.com/bundleuser") end end + end - context "git is not installed in the system" do - before do - FileUtils.rm ENV["GIT_CONFIG"].to_s if File.exist?(ENV["GIT_CONFIG"]) - reset! - in_app_root - bundle "gem #{gem_name}" - remove_push_guard(gem_name) - end + it "creates a new git repository" do + in_app_root + bundle "gem test_gem" + expect(bundled_app("test_gem/.git")).to exist + end - it "contribute URL set to [USERNAME]" do - expect(bundled_app("test_gem/README.md").read).to include("[USERNAME]") - expect(bundled_app("test_gem/README.md").read).not_to include("github.com/bundleuser") - end + context "when git is not avaiable" do + let(:gem_name) { "test_gem" } - it_should_behave_like "git config is absent" + # This spec cannot have `git` avaiable in the test env + before do + bundle_bin = File.expand_path("../../../exe/bundle", __FILE__) + load_paths = [lib, spec] + load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}" + + sys_exec "PATH=\"\" #{Gem.ruby} #{load_path_str} #{bundle_bin} gem #{gem_name}" + end + + it "creates the gem without the need for git" do + expect(bundled_app("#{gem_name}/README.md")).to exist + end + + it "doesn't create a git repo" do + expect(bundled_app("#{gem_name}/.git")).to_not exist + end + + it "doesn't create a .gitignore file" do + expect(bundled_app("#{gem_name}/.gitignore")).to_not exist end end |