From ad92651d6428d59b7f4dbee7014f4d1127bbdbe8 Mon Sep 17 00:00:00 2001 From: gabriele renzi Date: Thu, 30 Sep 2021 13:51:08 +0200 Subject: [PATCH] [rubygems/rubygems] Add glob infomation to Bundler::Source::Git#to_s 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. https://github.com/rubygems/rubygems/commit/493b880abc --- lib/bundler/source/git.rb | 22 ++++++++++-- spec/bundler/bundler/source/git_spec.rb | 45 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index fb13ca0578..679fb22574 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -42,7 +42,7 @@ module Bundler %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 @@ -75,12 +75,20 @@ module Bundler 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 @@ -282,6 +290,14 @@ module Bundler 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 diff --git a/spec/bundler/bundler/source/git_spec.rb b/spec/bundler/bundler/source/git_spec.rb index 6668b6e69a..ed6dc3cd29 100644 --- a/spec/bundler/bundler/source/git_spec.rb +++ b/spec/bundler/bundler/source/git_spec.rb @@ -24,5 +24,50 @@ RSpec.describe Bundler::Source::Git do 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