Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if bundler version older than in lockfile #8

Open
wants to merge 34 commits into
base: 2-0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e4181c9
Create rspec test that prints to lockfile
jhhere Oct 1, 2013
d1db691
Prints out BUNDLER after DEPENDENCIES
jhhere Oct 1, 2013
acf250d
Add bundler version to first spec test
jhhere Oct 2, 2013
d523de5
Add bundler version to out
jhhere Oct 2, 2013
2008cc2
Change bundler version in lockfile to newer version than the version …
jhhere Oct 2, 2013
b390d4b
Stores bundler version
jhhere Oct 2, 2013
b6fa002
The second test adds bundle :install to include text
jhhere Oct 3, 2013
518ab34
Add attr_reader and remove ||=
jhhere Oct 3, 2013
a940844
method to see if Bundler version in lockfile is newer than the curren…
jhhere Oct 3, 2013
7b27bfa
Prints error msg if lockfile Bundler version newer than current Bundl…
jhhere Oct 3, 2013
e41ca07
Throws up error :/ /lib/bundler.rb:320:in initialize': No such file o…
jhhere Oct 3, 2013
28be5bc
Change code if there isn't a lockfile in locked_gem method and locked…
jhhere Oct 3, 2013
916e7e8
Add bundle install expect out msg in spec test
jhhere Oct 3, 2013
c068c86
put a high version directly into the lockfile
indirect Oct 4, 2013
8c92027
remove comment so expected lockfile is correct
indirect Oct 4, 2013
cdd978b
parse the bundler version out of the lock
indirect Oct 4, 2013
4176b2b
switch to a warning for old bundlers
indirect Oct 4, 2013
ffaa321
rename LockfileParser#bundler to bundler_version
indirect Oct 4, 2013
d31ea37
rename Bundler.locked_gems to Bundler.lock
indirect Oct 4, 2013
779b9fd
just use Bundler.lock.bundler_version
indirect Oct 4, 2013
4ffaba4
save the locking bundler version before re-locking
indirect Oct 4, 2013
41e02ab
Add gemfile to first spec test
jhhere Oct 2, 2013
7509d31
Add code to fix rspec errors
jhhere Oct 4, 2013
615450b
Remove lockfile in spec test
jhhere Oct 4, 2013
fc976f0
Add bundler version to lockfile_should_be() method
jhhere Oct 8, 2013
5341c85
fix failing specs
jhhere Oct 9, 2013
f09bf73
make the spec test for 'fixes corrupted lockfiles' pass
jhhere Oct 9, 2013
fe94b13
Remove --all option from bundle update
jhhere Oct 9, 2013
9ba0128
Fix spec test's msg for bundle update
jhhere Oct 9, 2013
fd1d799
change bundle update to bundle update --force
jhhere Oct 9, 2013
ba0103c
change bundle update to bundle update --force
jhhere Oct 10, 2013
27eea6f
remove ::
jhhere Oct 10, 2013
0b1932c
Change file permission to allow to write to Gemfile.lock
jhhere Oct 10, 2013
2d115e0
I don't think this is right, o well
jhhere Oct 11, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ def definition(unlock = nil)
end
end

def locked_gems
@locked_gems ||= begin
def lock
return @lock if defined?(@lock)
if Bundler.default_lockfile.exist?
lock = Bundler.read_file(Bundler.default_lockfile)
LockfileParser.new(lock)
@lock = LockfileParser.new(lock)
else
@lock = nil
end
end

Expand Down
17 changes: 9 additions & 8 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def install
Bundler.ui.level = "warn" if opts[:quiet]
Bundler::Fetcher.disable_endpoint = opts["full-index"]
Bundler.settings[:disable_shared_gems] = Bundler.settings[:path] ? '1' : nil
locking_bundler_version = Bundler.lock.bundler_version if Bundler.lock

# rubygems plugins sometimes hook into the gem install process
Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
Expand All @@ -274,6 +275,12 @@ def install
end

clean if Bundler.settings[:clean] && Bundler.settings[:path]

if locking_bundler_version && locking_bundler_version > Gem::Version.new(Bundler::VERSION)
Bundler.ui.warn "You're using an older version of Bundler (#{Bundler::VERSION}) than " \
"the one specified in your Gemfile (#{locking_bundler_version})!" \
" Please upgrade by running `gem install bundler`."
end
rescue GemNotFound, VersionConflict => e
if opts[:local] && Bundler.app_cache.exist?
Bundler.ui.warn "Some gems seem to be missing from your vendor/cache directory."
Expand Down Expand Up @@ -303,25 +310,19 @@ def install
"Only output warnings and errors."
method_option "full-index", :type => :boolean, :banner =>
"Use the rubygems modern index instead of the API endpoint"
method_option "all", :type => :boolean, :banner =>
"updates all gems"
def update(*gems)
sources = Array(options[:source])
Bundler.ui.level = "warn" if options[:quiet]

if gems.empty? && !options[:force]
Bundler.ui.error "Run `bundle update GEM` to update a specific gem. Run `bundle update --force` if you really want to update all gems."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these lines need to come back for bundle update to keep working

exit 1
end

if !options[:all] && gems.empty? && sources.empty?
return Bundler.ui.info("Are you sure you want to update every single gem in your bundle?!\n\nIf yes, run bundle update --all.\nIf you want to update an individual gem, run bundle update <gem_name>.\nIf not, have a good day!")
elsif options[:all] && gems.empty? && sources.empty?
elsif options[:force] && gems.empty? && sources.empty?
# We're doing a full update
Bundler.definition(true)
else
# cycle through the requested gems, just to make sure they exist
names = Bundler.locked_gems.specs.map{ |s| s.name }
names = Bundler.lock.specs.map{ |s| s.name }
gems.each do |g|
next if names.include?(g)
raise GemNotFound, not_found_message(g, names)
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ def to_lock
handled << dep.name
end

out << "\n"
out << "BUNDLER\n"
out << " #{Bundler::VERSION}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after thinking about this a bit more, I think this should be [Bundler.lock.bundler_version, Gem::Version.new(Bundler::VERSION)].max, so that older versions of bundler will not lower this number when they run.


out
end

Expand Down
11 changes: 10 additions & 1 deletion lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms
attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version

DEPENDENCIES = "DEPENDENCIES"
PLATFORMS = "PLATFORMS"
BUNDLER = "BUNDLER"
GIT = "GIT"
GEM = "GEM"
PATH = "PATH"
Expand All @@ -39,6 +40,8 @@ def initialize(lockfile)
@state = :dependency
elsif line == PLATFORMS
@state = :platform
elsif line == BUNDLER
@state = :bundler
else
send("parse_#{@state}", line)
end
Expand Down Expand Up @@ -140,5 +143,11 @@ def parse_platform(line)
end
end

def parse_bundler(line)
if line =~ /^ (.*)$/
@bundler_version = Gem::Version.new($1)
end
end

end
end
2 changes: 1 addition & 1 deletion lib/bundler/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module Bundler
# We're doing this because we might write tests that deal
# with other versions of bundler and we are unsure how to
# handle this better.
VERSION = "1.4.0.rc.1" unless defined?(::Bundler::VERSION)
VERSION = "1.4.0.rc.1" unless defined?(Bundler::VERSION)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the :: on, I remember there was a bug at some point that meant this only worked with it

end
2 changes: 1 addition & 1 deletion spec/install/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@
end
G

bundle "update", :env => {"PATH" => ""}
bundle "update --force", :env => {"PATH" => ""}
expect(out).to include("You need to install git to be able to use gems from git repositories. For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git")
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/install/post_bundle_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:bundle_show_message) {"Use `bundle show [gemname]` to see where a bundled gem is installed."}
let(:bundle_deployment_message) {"It was installed into ./vendor"}
let(:bundle_complete_message) {"Your bundle is complete!"}
let(:bundle_updated_message) {"Your bundle is updated!"}
let(:bundle_updated_message) {"Run `bundle update GEM` to update a specific gem. Run `bundle update --force` if you really want to update all gems."}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of changing the message you should be able to change all three bundle :update below to be bundle "update --force" instead


describe "for fresh bundle install" do
it "without any options" do
Expand Down Expand Up @@ -120,22 +120,22 @@

it "with --without one group" do
bundle :install, :without => :emo
bundle :update
expect(out).to include("Gems in the group emo were not installed")
bundle :update
expect(out).to include(bundle_updated_message)
end

it "with --without two groups" do
bundle "install --without emo test"
bundle :update
expect(out).to include("Gems in the groups emo and test were not installed")
bundle :update
expect(out).to include(bundle_updated_message)
end

it "with --without more groups" do
bundle "install --without emo obama test"
bundle :update
expect(out).to include("Gems in the groups emo, obama and test were not installed")
bundle :update
expect(out).to include(bundle_updated_message)
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/lock/lockfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@

DEPENDENCIES
omg!

BUNDLER
#{Bundler::VERSION}
L
end

Expand All @@ -775,17 +778,19 @@ def set_lockfile_mtime_to_known_value
source "file://#{gem_repo2}"
gem "rack"
G
set_lockfile_mtime_to_known_value
#set_lockfile_mtime_to_known_value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this can be commented out then just delete it I think

end

it "generates Gemfile.lock with \\n line endings" do
set_lockfile_mtime_to_known_value
expect(File.read(bundled_app("Gemfile.lock"))).not_to match("\r\n")
should_be_installed "rack 1.0"
end

context "during updates" do

it "preserves Gemfile.lock \\n line endings" do
set_lockfile_mtime_to_known_value
update_repo2

expect { bundle "update --force" }.to change { File.mtime(bundled_app('Gemfile.lock')) }
Expand All @@ -794,6 +799,7 @@ def set_lockfile_mtime_to_known_value
end

it "preserves Gemfile.lock \\n\\r line endings" do
set_lockfile_mtime_to_known_value
update_repo2
win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n")
File.open(bundled_app("Gemfile.lock"), "wb"){|f| f.puts(win_lock) }
Expand All @@ -808,6 +814,7 @@ def set_lockfile_mtime_to_known_value
context "when nothing changes" do

it "preserves Gemfile.lock \\n line endings" do
File.mtime(bundled_app('Gemfile.lock'))
expect { ruby <<-RUBY
require 'rubygems'
require 'bundler'
Expand All @@ -817,9 +824,9 @@ def set_lockfile_mtime_to_known_value
end

it "preserves Gemfile.lock \\n\\r line endings" do
mtime = File.mtime(bundled_app('Gemfile.lock'))
win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n")
File.open(bundled_app("Gemfile.lock"), "wb"){|f| f.puts(win_lock) }
set_lockfile_mtime_to_known_value

expect { ruby <<-RUBY
require 'rubygems'
Expand Down
2 changes: 1 addition & 1 deletion spec/other/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def should_be_patchlevel_incorrect(opts = {:exitstatus => true})
build_gem "activesupport", "3.0"
end

bundle :update, :exitstatus => true
bundle 'update --force', :exitstatus => true
should_be_patchlevel_incorrect
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
Dir["**/*"].each do |f|
File.directory?(f) ?
File.chmod(0555, f) :
File.chmod(0444, f)
File.chmod(0644, f)
end
should_be_installed "rack 1.0.0"
ensure
Expand Down
2 changes: 2 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def lockfile_should_be(expected)
should_be_locked
spaces = expected[/\A\s+/, 0] || ""
expected.gsub!(/^#{spaces}/, '')
bundler_version = "\nBUNDLER\n #{Bundler::VERSION}\n"
expected.gsub!(/\z/, bundler_version) unless expected.match(/BUNDLER/)
expect(bundled_app("Gemfile.lock").read).to eq(expected)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/update/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "bundle update" do
it "prints a message" do
bundle "update"
expect(out).to include("Are you sure you want to update every single gem in your bundle?!\n\nIf yes, run bundle update --all.\nIf you want to update an individual gem, run bundle update <gem_name>.\nIf not, have a good day!")
expect(out).to include("Run `bundle update GEM` to update a specific gem. Run `bundle update --force` if you really want to update all gems.")
end

it "does not print bundle was updated" do
Expand All @@ -12,7 +12,7 @@
end
end

describe "bundle update --all" do
describe "bundle update --force" do
before :each do
build_repo2

Expand Down
90 changes: 90 additions & 0 deletions spec/warn-bundler-version-older-than-in-lockfile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require "spec_helper"

describe "lockfile" do
include Bundler::GemHelpers

it "prints out the Bundler version that generated the lockfile" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be in the file spec/lock/lockfile_spec.rb


install_gemfile <<-G
source "file://#{gem_repo1}"

gem "rails"
G

lockfile_should_be <<-G
GEM
remote: file:#{gem_repo1}/
specs:
actionmailer (2.3.2)
activesupport (= 2.3.2)
actionpack (2.3.2)
activesupport (= 2.3.2)
activerecord (2.3.2)
activesupport (= 2.3.2)
activeresource (2.3.2)
activesupport (= 2.3.2)
activesupport (2.3.2)
rails (2.3.2)
actionmailer (= 2.3.2)
actionpack (= 2.3.2)
activerecord (= 2.3.2)
activeresource (= 2.3.2)
rake (= 10.0.2)
rake (10.0.2)

PLATFORMS
#{generic(Gem::Platform.local)}

DEPENDENCIES
rails

BUNDLER
#{Bundler::VERSION}
G

end

it "warns if the bundler version is older than the version that created" do
gemfile <<-G
source "file://#{gem_repo1}"

gem "rails"
G

lockfile <<-L
GEM
remote: file:#{gem_repo1}/
specs:
actionmailer (2.3.2)
activesupport (= 2.3.2)
actionpack (2.3.2)
activesupport (= 2.3.2)
activerecord (2.3.2)
activesupport (= 2.3.2)
activeresource (2.3.2)
activesupport (= 2.3.2)
activesupport (2.3.2)
rails (2.3.2)
actionmailer (= 2.3.2)
actionpack (= 2.3.2)
activerecord (= 2.3.2)
activeresource (= 2.3.2)
rake (= 10.0.2)
rake (10.0.2)

PLATFORMS
#{generic(Gem::Platform.local)}

DEPENDENCIES
rails

BUNDLER
100.1
L

bundle :install
expect(out).to include("You're using an older version of Bundler (#{
Bundler::VERSION}) than the one specified in your Gemfile (100.1)")
end

end