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

Commit

Permalink
Merge #7264
Browse files Browse the repository at this point in the history
7264: Consistent lockfiles r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was that when a Gemfile would specify path sources with paths starting with "./", the generated lockfile would be inconsistent on `bundle install` and `bundle update`.

### What was your diagnosis of the problem?

My diagnosis was that when running `bundle update`, the bundle would be unlocked, and bundler would order the path sources according to the path present in the Gemfile ("./aaa" for example). On the other hand, when running `bundle install`, bundler would read the relative paths from the lockfile, where they are normalized ("aaa" for example).

### What is your fix for the problem, implemented in this PR?

My fix is to normalize relative paths when creating the source list, so that "aaa" is always used over "./aaa".

### Why did you choose this fix out of the possible options?

I chose this fix because it fixes the problem and it's backwards compatible (as in, it doesn't break any specs that assert for specific lockfiles).

Fixes #7262.

Co-authored-by: David Rodríguez <[email protected]>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Aug 4, 2019
2 parents e1c5183 + c7532ce commit dec810e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/bundler/source/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ def initialize(options)
@allow_cached = false
@allow_remote = false

@root_path = options["root_path"] || Bundler.root
@root_path = options["root_path"] || root

if options["path"]
@path = Pathname.new(options["path"])
@path = expand(@path) unless @path.relative?
expanded_path = expand(@path)
@path = if @path.relative?
expanded_path.relative_path_from(root_path.expand_path)
else
expanded_path
end
end

@name = options["name"]
Expand Down Expand Up @@ -136,7 +141,7 @@ def expand(somepath)

def lockfile_path
return relative_path(original_path) if original_path.absolute?
expand(original_path).relative_path_from(Bundler.root)
expand(original_path).relative_path_from(root)
end

def app_cache_path(custom_path = nil)
Expand Down
56 changes: 50 additions & 6 deletions spec/install/gemfile/path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,50 @@
end
end

it "sorts paths consistently on install and update when they start with ./" do
build_lib "demo", :path => lib_path("demo")
build_lib "aaa", :path => lib_path("demo/aaa")

gemfile = <<-G
gemspec
gem "aaa", :path => "./aaa"
G

File.open(lib_path("demo/Gemfile"), "w") {|f| f.puts gemfile }

lockfile = <<~L
PATH
remote: .
specs:
demo (1.0)
PATH
remote: aaa
specs:
aaa (1.0)
GEM
specs:
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
aaa!
demo!
BUNDLED WITH
#{Bundler::VERSION}
L

Dir.chdir(lib_path("demo")) do
bundle :install
expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile)
bundle :update, :all => true
expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile)
end
end

it "expands paths when comparing locked paths to Gemfile paths" do
build_lib "foo", :path => bundled_app("foo-1.0")

Expand Down Expand Up @@ -370,13 +414,13 @@
end

it "works when the path does not have a gemspec but there is a lockfile" do
lockfile <<-L
PATH
remote: vendor/bar
specs:
lockfile <<~L
PATH
remote: vendor/bar
specs:
GEM
remote: http://rubygems.org
GEM
remote: http://rubygems.org
L

in_app_root { FileUtils.mkdir_p("vendor/bar") }
Expand Down

0 comments on commit dec810e

Please sign in to comment.