summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-05-26 11:15:24 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-06-14 10:15:47 -0500
commit65aca787cc329c8c655eaccedf0ea50fa5a47153 (patch)
tree19f84413928d87a50d78c2cada9310489382d69f
parente274d9fe47a0f1801761e4646ce5df32df6033ac (diff)
downloadbundler-65aca787cc329c8c655eaccedf0ea50fa5a47153.tar.gz
[Pristine] Allow passing a list of gems to pristine
-rw-r--r--lib/bundler/cli.rb6
-rw-r--r--lib/bundler/cli/pristine.rb5
-rw-r--r--spec/commands/pristine_spec.rb31
3 files changed, 39 insertions, 3 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 10287d3ac7..c9ddec93f4 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -553,10 +553,10 @@ module Bundler
Issue.new.run
end
- desc "pristine", "Restores installed gems to pristine condition from files located in the gem cache. Gem installed from a git repository will be issued `git checkout --force`."
- def pristine
+ desc "pristine [GEMS...]", "Restores installed gems to pristine condition from files located in the gem cache. Gem installed from a git repository will be issued `git checkout --force`."
+ def pristine(*gems)
require "bundler/cli/pristine"
- Pristine.new.run
+ Pristine.new(gems).run
end
if Bundler.feature_flag.plugins?
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb
index 86b7b86eaa..ccf970eae0 100644
--- a/lib/bundler/cli/pristine.rb
+++ b/lib/bundler/cli/pristine.rb
@@ -3,9 +3,14 @@ require "bundler/cli/common"
module Bundler
class CLI::Pristine
+ def initialize(gems)
+ @gems = gems
+ end
+
def run
Bundler.load.specs.each do |spec|
next if spec.name == "bundler" # Source::Rubygems doesn't install bundler
+ next if !@gems.empty? && !@gems.include?(spec.name)
gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})"
gem_name += " (#{spec.platform})" if !spec.platform.nil? && spec.platform != Gem::Platform::RUBY
diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb
index 2bf9d46c66..5b9dffce98 100644
--- a/spec/commands/pristine_spec.rb
+++ b/spec/commands/pristine_spec.rb
@@ -109,4 +109,35 @@ RSpec.describe "bundle pristine" do
expect(changes_txt).to be_file
end
end
+
+ context "when passing a list of gems to pristine" do
+ it "resets them" do
+ foo = Bundler.definition.specs["foo"].first
+ foo_changes_txt = Pathname.new(foo.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(foo_changes_txt)
+ expect(foo_changes_txt).to be_file
+ foo_ref = Spec::Builders::GitReader.new(lib_path("foo")).ref_for("HEAD", 6)
+
+ bar = Bundler.definition.specs["bar"].first
+ bar_changes_txt = Pathname.new(bar.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(bar_changes_txt)
+ expect(bar_changes_txt).to be_file
+
+ weakling = Bundler.definition.specs["weakling"].first
+ weakling_changes_txt = Pathname.new(weakling.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(weakling_changes_txt)
+ expect(weakling_changes_txt).to be_file
+
+ bundle! "pristine foo bar weakling bundler"
+
+ expect(out).to eq(strip_whitespace(<<-EOS).strip)
+ Installing weakling 1.0
+ Using foo 1.0 from #{lib_path("foo")} (at master@#{foo_ref})
+ Cannot pristine bar (1.0). Gem is sourced from local path.
+ EOS
+ expect(weakling_changes_txt).not_to be_file
+ expect(foo_changes_txt).not_to be_file
+ expect(bar_changes_txt).to be_file
+ end
+ end
end