Skip to content

Commit

Permalink
Add glob infomation to Bundler::Source::Git#to_s
Browse files Browse the repository at this point in the history
The glob information was not specified in the string representation for
a source, which led to non-deterministic behaviour when generating the
lockfile, since sources are sorted by this value.
  • Loading branch information
riffraff committed Oct 1, 2021
1 parent d01d6ca commit 493b880
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
22 changes: 19 additions & 3 deletions bundler/lib/bundler/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_lock
%w[ref branch tag submodules].each do |opt|
out << " #{opt}: #{options[opt]}\n" if options[opt]
end
out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
out << " glob: #{@glob}\n" unless default_glob?
out << " specs:\n"
end

Expand Down Expand Up @@ -75,12 +75,20 @@ def to_s
git_proxy.branch
end

rev = " (at #{at}@#{shortref_for_display(revision)})"
rev = "at #{at}@#{shortref_for_display(revision)}"
rescue GitError
""
end

"#{@safe_uri}#{rev}"
specifiers = [rev, glob_for_display].compact
suffix =
if specifiers.any?
" (#{specifiers.join(", ")})"
else
""
end

"#{@safe_uri}#{suffix}"
end

def name
Expand Down Expand Up @@ -282,6 +290,14 @@ def shortref_for_path(ref)
ref[0..11]
end

def glob_for_display
default_glob? ? nil : "glob: #{@glob}"
end

def default_glob?
@glob == DEFAULT_GLOB
end

def uri_hash
if uri =~ %r{^\w+://(\w+@)?}
# Downcase the domain component of the URI
Expand Down
45 changes: 45 additions & 0 deletions bundler/spec/bundler/source/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,50 @@
expect(subject.to_s).to eq "https://x-oauth-basic@github.com/foo/bar.git"
end
end

context "when the source has a glob specifier" do
let(:glob) { "bar/baz/*.gemspec" }
let(:options) do
{ "uri" => uri, "glob" => glob }
end

it "includes it" do
expect(subject.to_s).to eq "https://github.com/foo/bar.git (glob: bar/baz/*.gemspec)"
end
end

context "when the source has a reference" do
let(:git_proxy_stub) do
instance_double(Bundler::Source::Git::GitProxy, :revision => "123abc", :branch => "v1.0.0")
end
let(:options) do
{ "uri" => uri, "ref" => "v1.0.0" }
end

before do
allow(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
end

it "includes it" do
expect(subject.to_s).to eq "https://github.com/foo/bar.git (at v1.0.0@123abc)"
end
end

context "when the source has both reference and glob specifiers" do
let(:git_proxy_stub) do
instance_double(Bundler::Source::Git::GitProxy, :revision => "123abc", :branch => "v1.0.0")
end
let(:options) do
{ "uri" => uri, "ref" => "v1.0.0", "glob" => "gems/foo/*.gemspec" }
end

before do
allow(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
end

it "includes both" do
expect(subject.to_s).to eq "https://github.com/foo/bar.git (at v1.0.0@123abc, glob: gems/foo/*.gemspec)"
end
end
end
end

0 comments on commit 493b880

Please sign in to comment.