diff options
author | Yehuda Katz <yehudakatz@Billing-MacBook-Pro.local> | 2010-02-04 10:47:07 -0800 |
---|---|---|
committer | Yehuda Katz <yehudakatz@Billing-MacBook-Pro.local> | 2010-02-04 10:47:07 -0800 |
commit | 8835be6272442994da3e6959351724f456027cba (patch) | |
tree | 285e904e86e935bd60c9080e0070abdeee4b7217 | |
parent | e58283560dbcaf361308555051bd9ee6253650ac (diff) | |
download | bundler-8835be6272442994da3e6959351724f456027cba.tar.gz |
Print an error if the Gemfile changed after the lock
-rw-r--r-- | bundler.gemspec | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 14 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 3 | ||||
-rw-r--r-- | spec/lock/gems_spec.rb | 13 |
4 files changed, 30 insertions, 2 deletions
diff --git a/bundler.gemspec b/bundler.gemspec index b208291800..477f87cd4a 100644 --- a/bundler.gemspec +++ b/bundler.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.default_executable = %q{bundle} s.email = ["carlhuda@engineyard.com"] s.executables = ["bundle"] - s.files = ["bin/bundle", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/runtime.rb", "lib/bundler/settings.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"] + s.files = ["bin/bundle", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/runtime.rb", "lib/bundler/settings.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor", "lib/bundler/vendor/thor", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/shell", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"] s.homepage = %q{http://github.com/carlhuda/bundler} s.post_install_message = %q{Due to a rubygems bug, you must uninstall all older versions of bundler for 0.9 to work} s.require_paths = ["lib"] diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 06a413ca94..9048b2ac8d 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -1,3 +1,5 @@ +require "digest/sha1" + module Bundler class Definition def self.from_gemfile(gemfile) @@ -13,7 +15,13 @@ module Bundler def self.from_lock(lockfile) # gemfile_definition = from_gemfile(nil) locked_definition = Locked.new(YAML.load_file(lockfile)) - # raise GemfileError unless gemfile_definition.equivalent?(locked_definition) + + # TODO: Switch to using equivalent? + hash = Digest::SHA1.hexdigest(File.read("#{Bundler.root}/Gemfile")) + unless locked_definition.hash == hash + raise GemfileError, "You changed your Gemfile after locking. Please relock using `gem lock`" + end + locked_definition end @@ -55,6 +63,10 @@ module Bundler @details = details end + def hash + @details["hash"] + end + def sources @sources ||= @details["sources"].map do |args| name, options = args.to_a.flatten diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index f582220452..75eaf9b8d3 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -1,3 +1,5 @@ +require "digest/md5" + module Bundler class Runtime < Environment def setup(*groups) @@ -159,6 +161,7 @@ module Bundler def details details = {} + details["hash"] = Digest::SHA1.hexdigest(File.read("#{root}/Gemfile")) details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} } details["specs"] = specs.map do |s| diff --git a/spec/lock/gems_spec.rb b/spec/lock/gems_spec.rb index 4832f1006e..20c3fd1add 100644 --- a/spec/lock/gems_spec.rb +++ b/spec/lock/gems_spec.rb @@ -49,4 +49,17 @@ describe "gemfile lock with gems" do should_be_available "rack 1.0.0" end end + + it "exits gracefully if the Gemfile changes after lock" do + bundle :lock + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + + bundle :install + + out.should =~ /You changed your Gemfile after locking. Please relock using `gem lock`/ + end end
\ No newline at end of file |