diff options
author | Dennis Suratna <dennis.suratna@gmail.com> | 2017-03-07 10:33:32 -0800 |
---|---|---|
committer | Dennis Suratna <dennis.suratna@gmail.com> | 2017-04-11 18:33:29 +0700 |
commit | 2ef1e3e6c4991a25f9bf4fc1c3190e7270ccc649 (patch) | |
tree | 03fc350a05d4aceb085e837a1e0e62f869cfb4a5 | |
parent | 03bfeaaf842210519a9b057d2e0475daa60d7090 (diff) | |
download | bundler-2ef1e3e6c4991a25f9bf4fc1c3190e7270ccc649.tar.gz |
Expand test and refactor to re-install using source
-rw-r--r-- | lib/bundler/cli/pristine.rb | 17 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 3 | ||||
-rw-r--r-- | spec/commands/pristine_spec.rb | 32 |
3 files changed, 24 insertions, 28 deletions
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb index 64772c70d2..8a8318ede7 100644 --- a/lib/bundler/cli/pristine.rb +++ b/lib/bundler/cli/pristine.rb @@ -4,34 +4,29 @@ require "bundler/cli/common" module Bundler class CLI::Pristine def run - ::Bundler.load.specs.each do |spec| - gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})" if spec.source.instance_of? Source::Path - ::Bundler.ui.warn("Cannot pristine #{gem_name} Gem is sourced from path.") + ::Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.") next end if spec.source.instance_of? Source::Rubygems cached_gem = spec.cache_file - unless File.exists?(cached_gem) + unless File.exist?(cached_gem) # TODO: Refetch from ruby gem? ::Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.") next end - Gem::Installer.at(cached_gem, - :wrappers => true, - :force => true, - :install_dir => spec.base_dir, - :build_args => spec.build_args).install + spec.source.install(spec, :force => true) elsif spec.source.instance_of? Source::Git - `git -C "#{spec.full_gem_path}" checkout --force` + git_source = spec.source + git_source.remote! + git_source.install(spec, :force => true) end - end end end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index c95c94583f..335ad352be 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -171,7 +171,10 @@ module Bundler git_proxy.copy_to(install_path, submodules) serialize_gemspecs_in(install_path) @copied = true + elsif force + git_proxy.copy_to(install_path, submodules) end + generate_bin_options = { :disable_extensions => !Bundler.rubygems.spec_missing_extensions?(spec), :build_args => options[:build_args] } generate_bin(spec, generate_bin_options) diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index ec44b68930..422d5eb958 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -22,7 +22,6 @@ RSpec.describe "bundle pristine" do context "when sourced from Rubygems" do it "reverts using cached .gem file" do - spec = Bundler.definition.specs["weakling"].first changes_txt = "#{spec.full_gem_path}/lib/changes.txt" @@ -31,33 +30,32 @@ RSpec.describe "bundle pristine" do bundle "pristine" expect(File.exist?(changes_txt)).to be_falsey - end end context "when sourced from git repo" do - it "reverts by issuing `git checkout --force`" do - + it "reverts by resetting to current revision`" do spec = Bundler.definition.specs["foo"].first changed_file = "#{spec.full_gem_path}/lib/foo.rb" + diff = "#Pristine spec changes" `echo '#Pristine spec changes' >> #{changed_file}` - expect(File.read(changed_file)).to include('#Pristine spec changes') + expect(File.read(changed_file)).to include(diff) bundle "pristine" - expect(File.read(changed_file)).to_not include('#Pristine spec changes') - + expect(File.read(changed_file)).to_not include(diff) end end - # context "when sourced from path" do - # it "ignores and warns sourced from local path" do - # - # spec = Bundler.definition.specs["bar"].first - # expect(Bundler.ui).to receive(:warn).with("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}) Gem is sourced from path.") - # bundle "pristine" - # - # end - # end - + context "when sourced from path" do + it "displays warning and ignores changes sourced from local path" do + spec = Bundler.definition.specs["bar"].first + changes_txt = "#{spec.full_gem_path}/lib/changes.txt" + FileUtils.touch(changes_txt) + expect(File.exist?(changes_txt)).to be_truthy + bundle "pristine" + expect(out).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is sourced from local path.") + expect(File.exist?(changes_txt)).to be_truthy + end + end end |