[rubygems/rubygems] Fix strange error when running bundle add
with frozen mode set
If Gemfile is empty and there's no lockfile (situation after `bundle init`), and `frozen` is configured, running `bundle add` will result in an strange error, like this: ``` $ bundle add rake , but the lockfile can't be updated because frozen mode is set You have deleted from the Gemfile: * rake (~> 13.2) Run `bundle install` elsewhere and add the updated Gemfile to version control. ``` This commit fixes the problem to instead print https://github.com/rubygems/rubygems/commit/152331a9dc
This commit is contained in:
parent
182822683f
commit
7e612b7414
@ -367,6 +367,10 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
|
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
|
||||||
|
return unless Bundler.frozen_bundle?
|
||||||
|
|
||||||
|
raise ProductionError, "Frozen mode is set, but there's no lockfile" unless lockfile_exists?
|
||||||
|
|
||||||
added = []
|
added = []
|
||||||
deleted = []
|
deleted = []
|
||||||
changed = []
|
changed = []
|
||||||
|
@ -23,10 +23,7 @@ module Bundler
|
|||||||
# @param [Pathname] lockfile_path The lockfile in which to inject the new dependency.
|
# @param [Pathname] lockfile_path The lockfile in which to inject the new dependency.
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
def inject(gemfile_path, lockfile_path)
|
def inject(gemfile_path, lockfile_path)
|
||||||
if Bundler.frozen_bundle?
|
|
||||||
# ensure the lock and Gemfile are synced
|
|
||||||
Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true)
|
Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true)
|
||||||
end
|
|
||||||
|
|
||||||
# temporarily unfreeze
|
# temporarily unfreeze
|
||||||
Bundler.settings.temporary(deployment: false, frozen: false) do
|
Bundler.settings.temporary(deployment: false, frozen: false) do
|
||||||
|
@ -69,9 +69,7 @@ module Bundler
|
|||||||
Bundler.create_bundle_path
|
Bundler.create_bundle_path
|
||||||
|
|
||||||
ProcessLock.lock do
|
ProcessLock.lock do
|
||||||
if Bundler.frozen_bundle?
|
|
||||||
@definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment])
|
@definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment])
|
||||||
end
|
|
||||||
|
|
||||||
if @definition.dependencies.empty?
|
if @definition.dependencies.empty?
|
||||||
Bundler.ui.warn "The Gemfile specifies no dependencies"
|
Bundler.ui.warn "The Gemfile specifies no dependencies"
|
||||||
|
@ -10,7 +10,7 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup(*groups)
|
def setup(*groups)
|
||||||
@definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen_bundle?
|
@definition.ensure_equivalent_gemfile_and_lockfile
|
||||||
|
|
||||||
# Has to happen first
|
# Has to happen first
|
||||||
clean_load_path
|
clean_load_path
|
||||||
|
@ -28,6 +28,15 @@ RSpec.describe "bundle add" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when Gemfile is empty, and frozen mode is set" do
|
||||||
|
it "shows error" do
|
||||||
|
gemfile 'source "https://gem.repo2"'
|
||||||
|
bundle "add bar", raise_on_error: false, env: { "BUNDLE_FROZEN" => "true" }
|
||||||
|
|
||||||
|
expect(err).to include("Frozen mode is set, but there's no lockfile")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "without version specified" do
|
describe "without version specified" do
|
||||||
it "version requirement becomes ~> major.minor.patch when resolved version is < 1.0" do
|
it "version requirement becomes ~> major.minor.patch when resolved version is < 1.0" do
|
||||||
bundle "add 'bar'"
|
bundle "add 'bar'"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user