Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #6273 - joelvh:feature/bundle_update_gemfile_option, r=…
Browse files Browse the repository at this point in the history
…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` (#6270).

(cherry picked from commit a0592e5)
  • Loading branch information
bundlerbot authored and colby-swandale committed Sep 20, 2018
1 parent 4da61c3 commit ebdcabf
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def install
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 =>
Expand Down
13 changes: 13 additions & 0 deletions spec/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
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" }

Expand Down
2 changes: 2 additions & 0 deletions spec/install/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

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
Expand Down
66 changes: 66 additions & 0 deletions spec/update/gemfile_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ebdcabf

Please sign in to comment.