summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-01-31 00:20:04 +0000
committerColby Swandale <me@colby.fyi>2018-10-05 16:15:43 +1000
commit2e4bae58271c20ece7ab8474145571532955dfac (patch)
tree5da7e8e0aba73bef4273c1bbad27174d590118b6
parentc4ffe1ff1ac9998d712acca4a885e5ba6a0e5613 (diff)
downloadbundler-2e4bae58271c20ece7ab8474145571532955dfac.tar.gz
Auto merge of #6273 - joelvh:feature/bundle_update_gemfile_option, r=colby-swandale
Added `--gemfile` option to `bundle update` Thanks so much for the contribution! To make reviewing this PR a bit easier, please fill out answers to the following questions. ### What was the end-user problem that led to this PR? The problem was that `BUNDLE_GEMFILE` is not respected when `.bundle/config` specifies an alternate Gemfile. However, my specific issue is that `bundle install --gemfile Gemfile2` is an option, but `bundle update` won't let me specify an alternate Gemfile. ### What was your diagnosis of the problem? My diagnosis was that Bundler copies `BUNDLE_GEMFILE` environment variable to `BUNDLE_ORIG_GEMFILE` and always uses `.bundle/config`. Simplest solution was to add parity to `bundle update` rather than diagnose why environment variables don't override `.bundle/config` settings across the board. ### What is your fix for the problem, implemented in this PR? My fix is to add the `--gemfile` option to `bundle update` for parity with `bundle install`. ### Why did you choose this fix out of the possible options? I chose this fix because this allows installing and updating alternative Gemfiles without untangling environment variables. It's the most direct use case that I'm having this issue with. Ideally, the environment variables specified for a command should be respected and override settings in `.bundle/config` (https://github.com/bundler/bundler/issues/6270). (cherry picked from commit a0592e5d8d4b5f21df61b554b4622f0121730d7b)
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--spec/commands/update_spec.rb13
-rw-r--r--spec/install/gemfile_spec.rb2
-rw-r--r--spec/update/gemfile_spec.rb66
4 files changed, 83 insertions, 0 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index db1782b71a..8ca3f4b9f6 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -233,6 +233,8 @@ module Bundler
D
method_option "full-index", :type => :boolean, :banner =>
"Fall back to using the single-file index of all gems"
+ method_option "gemfile", :type => :string, :banner =>
+ "Use the specified gemfile instead of Gemfile"
method_option "group", :aliases => "-g", :type => :array, :banner =>
"Update a specific group"
method_option "jobs", :aliases => "-j", :type => :numeric, :banner =>
diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb
index e8f5275118..6eb49d3acd 100644
--- a/spec/commands/update_spec.rb
+++ b/spec/commands/update_spec.rb
@@ -57,6 +57,19 @@ RSpec.describe "bundle update" do
end
end
+ describe "with --gemfile" do
+ it "creates lock files based on the Gemfile name" do
+ gemfile bundled_app("OmgFile"), <<-G
+ source "file://#{gem_repo1}"
+ gem "rack", "1.0"
+ G
+
+ bundle! "update --gemfile OmgFile", :all => bundle_update_requires_all?
+
+ expect(bundled_app("OmgFile.lock")).to exist
+ end
+ end
+
context "when update_requires_all_flag is set" do
before { bundle! "config update_requires_all_flag true" }
diff --git a/spec/install/gemfile_spec.rb b/spec/install/gemfile_spec.rb
index 5961bcbfbd..e74c5ffe59 100644
--- a/spec/install/gemfile_spec.rb
+++ b/spec/install/gemfile_spec.rb
@@ -21,6 +21,8 @@ RSpec.describe "bundle install" do
bundle :install, :gemfile => bundled_app("NotGemfile")
+ # Specify BUNDLE_GEMFILE for `the_bundle`
+ # to retrieve the proper Gemfile
ENV["BUNDLE_GEMFILE"] = "NotGemfile"
expect(the_bundle).to include_gems "rack 1.0.0"
end
diff --git a/spec/update/gemfile_spec.rb b/spec/update/gemfile_spec.rb
new file mode 100644
index 0000000000..f59f3a2d32
--- /dev/null
+++ b/spec/update/gemfile_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+RSpec.describe "bundle update" do
+ context "with --gemfile" do
+ it "finds the gemfile" do
+ gemfile bundled_app("NotGemfile"), <<-G
+ source "file://#{gem_repo1}"
+ gem 'rack'
+ G
+
+ bundle! :install, :gemfile => bundled_app("NotGemfile")
+ bundle! :update, :gemfile => bundled_app("NotGemfile"), :all => bundle_update_requires_all?
+
+ # Specify BUNDLE_GEMFILE for `the_bundle`
+ # to retrieve the proper Gemfile
+ ENV["BUNDLE_GEMFILE"] = "NotGemfile"
+ expect(the_bundle).to include_gems "rack 1.0.0"
+ end
+ end
+
+ context "with gemfile set via config" do
+ before do
+ gemfile bundled_app("NotGemfile"), <<-G
+ source "file://#{gem_repo1}"
+ gem 'rack'
+ G
+
+ bundle "config --local gemfile #{bundled_app("NotGemfile")}"
+ bundle! :install
+ end
+
+ it "uses the gemfile to update" do
+ bundle! "update", :all => bundle_update_requires_all?
+ bundle "list"
+
+ expect(out).to include("rack (1.0.0)")
+ end
+
+ it "uses the gemfile while in a subdirectory" do
+ bundled_app("subdir").mkpath
+ Dir.chdir(bundled_app("subdir")) do
+ bundle! "update", :all => bundle_update_requires_all?
+ bundle "list"
+
+ expect(out).to include("rack (1.0.0)")
+ end
+ end
+ end
+
+ context "with prefer_gems_rb set" do
+ before { bundle! "config prefer_gems_rb true" }
+
+ it "prefers gems.rb to Gemfile" do
+ create_file("gems.rb", "gem 'bundler'")
+ create_file("Gemfile", "raise 'wrong Gemfile!'")
+
+ bundle! :install
+ bundle! :update, :all => bundle_update_requires_all?
+
+ expect(bundled_app("gems.rb")).to be_file
+ expect(bundled_app("Gemfile.lock")).not_to be_file
+
+ expect(the_bundle).to include_gem "bundler #{Bundler::VERSION}"
+ end
+ end
+end