Skip to content

Commit

Permalink
bundle update should not change EOL in Gemfile.lock
Browse files Browse the repository at this point in the history
Convert LF to CRLF if the existing file has them (Windows /w git config
core.autocrlf=true).  Addresses issue rubygems#810
  • Loading branch information
robertwahler authored and indirect committed Nov 2, 2010
1 parent 2760d9b commit dc46ae4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ def lock(file)
return
end

# The lock file contents are always generated with LF EOL characters
# Convert LF to CRLF if the existing file has them (Windows /w git config core.autocrlf=true)
contents = contents.gsub(/\n/, "\r\n") if File.exists?(file) && File.read(file).match("\r\n")

File.open(file, 'wb') do |f|
f.puts contents
end
Expand Down
53 changes: 52 additions & 1 deletion spec/update/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,57 @@
should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end

it "doesn't change existing Gemfile.lock LF EOL" do
update_repo2 do
build_gem "activesupport", "3.0"
end

bundled_app("Gemfile.lock").should exist
lockfile = File.read(bundled_app("Gemfile.lock"))
lockfile = lockfile.gsub(/\r\n/, "\n") if lockfile.match("\r\n")
File.open(bundled_app("Gemfile.lock"), 'wb') do |f|
f.puts lockfile
end
lockfile.should_not match("\r\n")
bundle "update"
File.read(bundled_app("Gemfile.lock")).should_not match("\r\n")
should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end

it "doesn't change existing Gemfile.lock CRLF EOL" do
update_repo2 do
build_gem "activesupport", "3.0"
end

bundled_app("Gemfile.lock").should exist
lockfile = File.read(bundled_app("Gemfile.lock"))
lockfile = lockfile.gsub(/\n/, "\r\n") unless lockfile.match("\r\n")
File.open(bundled_app("Gemfile.lock"), 'wb') do |f|
f.puts lockfile
end
lockfile.should match("\r\n")
bundle "update"
File.read(bundled_app("Gemfile.lock")).should match("\r\n")
should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end

it "creates Gemfile.lock EOL as LF by default" do
update_repo2 do
build_gem "activesupport", "3.0"
end

FileUtils.rm(bundled_app("Gemfile.lock"))
bundled_app("Gemfile.lock").should_not exist

bundle "update"

bundled_app("Gemfile.lock").should exist
lockfile = File.read(bundled_app("Gemfile.lock"))
lockfile.should_not match("\r\n")

should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end

it "doesn't delete the Gemfile.lock file if something goes wrong" do
gemfile <<-G
source "file://#{gem_repo2}"
Expand Down Expand Up @@ -109,4 +160,4 @@
out.should_not =~ /In snapshot/
out.should =~ /Current Bundler version/
end
end
end

0 comments on commit dc46ae4

Please sign in to comment.