Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'track_bundler_version_in_lock'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lance committed Mar 20, 2015
2 parents ea168ea + 1f4f1c9 commit eb99167
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 0 deletions.
Binary file added bundler-1.9.0.rc.gem
Binary file not shown.
30 changes: 30 additions & 0 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,39 @@ def lock(file)
"#{File.expand_path(file)}"
end

# Returns the version of Bundler that is creating or has created
# Gemfile.lock. Used in #to_lock.
def lock_version
lockfile = @lockfile_contents
lock_ver = ""
curr_ver = ""

if !lockfile.empty? and lockfile.match(/^ \[(.*)\]$/)
lock_ver = $1
curr_ver = Bundler::VERSION
end

if !lock_ver.empty? and !curr_ver.empty?
if Gem::Version.new(curr_ver) >= Gem::Version.new(lock_ver)
ver = curr_ver
else
ver = lock_ver
end
else
ver = Bundler::VERSION
end

ver
end

def to_lock
out = ""

# Record the version of Bundler that was used to create the lockfile
out << "LOCKED WITH\n"
out << " [#{lock_version}]\n"
out << "\n"

sources.lock_sources.each do |source|
# Add the source header
out << source.to_lock
Expand Down
17 changes: 17 additions & 0 deletions lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms

LOCKED = "LOCKED WITH"
DEPENDENCIES = "DEPENDENCIES"
PLATFORMS = "PLATFORMS"
GIT = "GIT"
Expand All @@ -31,6 +32,22 @@ def initialize(lockfile)

@rubygems_aggregate = Source::Rubygems.new


# If the lockfile's recorded version is older than the current version
# of Bundler, we warn the user to update Bundler.
if lockfile.match(/^ \[(.*)\]$/)
lock_ver = $1
curr_ver = Bundler::VERSION
prerelease_text = lock_ver.match(/pre/) ? " --pre" : ""

if Gem::Version.new(curr_ver) < Gem::Version.new(lock_ver)
Bundler.ui.warn "Warning: the running version of Bundler is older " \
"than the version that created the lockfile. We suggest you " \
"upgrade to the latest version of Bundler by running `gem " \
"install bundler#{prerelease_text}`.\n"
end
end

if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
raise LockfileError, "Your Gemfile.lock contains merge conflicts.\n" \
"Run `git checkout HEAD -- Gemfile.lock` first to get a clean lock."
Expand Down
Loading

0 comments on commit eb99167

Please sign in to comment.