From dc15dc56446ab10c17028810ac83eb577b375753 Mon Sep 17 00:00:00 2001 From: Robert Wahler Date: Thu, 18 Aug 2011 11:21:09 -0400 Subject: Gemfile.lock should not be touched if nothing has changed This fixes issue #1105, Gemfile.lock always updated on Windows when running bundle install --- lib/bundler/definition.rb | 8 +++---- spec/lock/lockfile_spec.rb | 60 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 962838aa..82e1aa3e 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -180,6 +180,10 @@ module Bundler def lock(file) contents = to_lock + # Convert to \r\n if the existing lock has them + # i.e., Windows with `git config core.autocrlf=true` + contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n") + return if @lockfile_contents == contents if Bundler.settings[:frozen] @@ -187,10 +191,6 @@ module Bundler return end - # Convert to \r\n if the existing lock has them - # i.e., Windows with `git config core.autocrlf=true` - contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n") - File.open(file, 'wb'){|f| f.puts(contents) } end diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 86663f23..e78eb41d 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -671,13 +671,18 @@ describe "the lockfile format" do end - context "line endings" do + describe "line endings" do + def set_lockfile_mtime_to_known_value + time = Time.local(2000, 1, 1, 0, 0, 0) + File.utime(time, time, bundled_app('Gemfile.lock')) + end before(:each) do build_repo2 install_gemfile <<-G source "file://#{gem_repo2}" gem "rack" G + set_lockfile_mtime_to_known_value end it "generates Gemfile.lock with \\n line endings" do @@ -685,22 +690,51 @@ describe "the lockfile format" do should_be_installed "rack 1.0" end - it "preserves Gemfile.lock \\n line endings" do - update_repo2 + context "during updates" do - bundle "update" - File.read(bundled_app("Gemfile.lock")).should_not match("\r\n") - should_be_installed "rack 1.2" + it "preserves Gemfile.lock \\n line endings" do + update_repo2 + + lambda { bundle "update" }.should change { File.mtime(bundled_app('Gemfile.lock')) } + File.read(bundled_app("Gemfile.lock")).should_not match("\r\n") + should_be_installed "rack 1.2" + end + + it "preserves Gemfile.lock \\n\\r line endings" do + 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) } + set_lockfile_mtime_to_known_value + + lambda { bundle "update" }.should change { File.mtime(bundled_app('Gemfile.lock')) } + File.read(bundled_app("Gemfile.lock")).should match("\r\n") + should_be_installed "rack 1.2" + end end - it "preserves Gemfile.lock \\n\\r line endings" do - 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) } + context "when nothing changes" do - bundle "update" - File.read(bundled_app("Gemfile.lock")).should match("\r\n") - should_be_installed "rack 1.2" + it "preserves Gemfile.lock \\n line endings" do + lambda { ruby <<-RUBY + require 'rubygems' + require 'bundler' + Bundler.setup + RUBY + }.should_not change { File.mtime(bundled_app('Gemfile.lock')) } + end + + it "preserves Gemfile.lock \\n\\r line endings" do + 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 + + lambda { ruby <<-RUBY + require 'rubygems' + require 'bundler' + Bundler.setup + RUBY + }.should_not change { File.mtime(bundled_app('Gemfile.lock')) } + end end end end -- cgit v1.2.3