Normalize git sources

Just like gem sources, a "style-only" change, like adding a trailing
slash, should not expire them.
This commit is contained in:
David Rodríguez 2023-01-17 20:53:52 +01:00 committed by Hiroshi SHIBATA
parent 7800d4eeb5
commit ddc4fd5644
6 changed files with 45 additions and 4 deletions

View File

@ -85,6 +85,7 @@ module Bundler
autoload :StubSpecification, File.expand_path("bundler/stub_specification", __dir__)
autoload :UI, File.expand_path("bundler/ui", __dir__)
autoload :URICredentialsFilter, File.expand_path("bundler/uri_credentials_filter", __dir__)
autoload :URINormalizer, File.expand_path("bundler/uri_normalizer", __dir__)
class << self
def configure

View File

@ -495,7 +495,7 @@ module Bundler
uri = $2
suffix = $3
end
uri = "#{uri}/" unless uri.end_with?("/")
uri = URINormalizer.normalize_suffix(uri)
require_relative "vendored_uri"
uri = Bundler::URI(uri)
unless uri.absolute?

View File

@ -19,7 +19,7 @@ module Bundler
# Stringify options that could be set as symbols
%w[ref branch tag revision].each {|k| options[k] = options[k].to_s if options[k] }
@uri = options["uri"] || ""
@uri = URINormalizer.normalize_suffix(options["uri"] || "", :trailing_slash => false)
@safe_uri = URICredentialsFilter.credential_filtered_uri(@uri)
@branch = options["branch"]
@ref = options["ref"] || options["branch"] || options["tag"]

View File

@ -337,8 +337,7 @@ module Bundler
end
def normalize_uri(uri)
uri = uri.to_s
uri = "#{uri}/" unless %r{/$}.match?(uri)
uri = URINormalizer.normalize_suffix(uri.to_s)
require_relative "../vendored_uri"
uri = Bundler::URI(uri)
raise ArgumentError, "The source must be an absolute URI. For example:\n" \

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
module Bundler
module URINormalizer
module_function
# Normalizes uri to a consistent version, either with or without trailing
# slash.
#
# TODO: Currently gem sources are locked with a trailing slash, while git
# sources are locked without a trailing slash. This should be normalized but
# the inconsistency is there for now to avoid changing all lockfiles
# including GIT sources. We could normalize this on the next major.
#
def normalize_suffix(uri, trailing_slash: true)
if trailing_slash
uri.end_with?("/") ? uri : "#{uri}/"
else
uri.end_with?("/") ? uri.delete_suffix("/") : uri
end
end
end
end

View File

@ -140,6 +140,24 @@ RSpec.describe "bundle lock" do
expect(read_lockfile).to eq(@lockfile)
end
it "does not unlock git sources when only uri shape changes" do
build_git("foo")
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}"
G
# Change uri format to end with "/" and reinstall
install_gemfile <<-G, :verbose => true
source "#{file_uri_for(gem_repo1)}"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}/"
G
expect(out).to include("using resolution from the lockfile")
expect(out).not_to include("re-resolving dependencies because the list of sources changed")
end
it "errors when updating a missing specific gems using --update" do
lockfile @lockfile