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:
parent
7800d4eeb5
commit
ddc4fd5644
@ -85,6 +85,7 @@ module Bundler
|
|||||||
autoload :StubSpecification, File.expand_path("bundler/stub_specification", __dir__)
|
autoload :StubSpecification, File.expand_path("bundler/stub_specification", __dir__)
|
||||||
autoload :UI, File.expand_path("bundler/ui", __dir__)
|
autoload :UI, File.expand_path("bundler/ui", __dir__)
|
||||||
autoload :URICredentialsFilter, File.expand_path("bundler/uri_credentials_filter", __dir__)
|
autoload :URICredentialsFilter, File.expand_path("bundler/uri_credentials_filter", __dir__)
|
||||||
|
autoload :URINormalizer, File.expand_path("bundler/uri_normalizer", __dir__)
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def configure
|
def configure
|
||||||
|
@ -495,7 +495,7 @@ module Bundler
|
|||||||
uri = $2
|
uri = $2
|
||||||
suffix = $3
|
suffix = $3
|
||||||
end
|
end
|
||||||
uri = "#{uri}/" unless uri.end_with?("/")
|
uri = URINormalizer.normalize_suffix(uri)
|
||||||
require_relative "vendored_uri"
|
require_relative "vendored_uri"
|
||||||
uri = Bundler::URI(uri)
|
uri = Bundler::URI(uri)
|
||||||
unless uri.absolute?
|
unless uri.absolute?
|
||||||
|
@ -19,7 +19,7 @@ module Bundler
|
|||||||
# Stringify options that could be set as symbols
|
# Stringify options that could be set as symbols
|
||||||
%w[ref branch tag revision].each {|k| options[k] = options[k].to_s if options[k] }
|
%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)
|
@safe_uri = URICredentialsFilter.credential_filtered_uri(@uri)
|
||||||
@branch = options["branch"]
|
@branch = options["branch"]
|
||||||
@ref = options["ref"] || options["branch"] || options["tag"]
|
@ref = options["ref"] || options["branch"] || options["tag"]
|
||||||
|
@ -337,8 +337,7 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def normalize_uri(uri)
|
def normalize_uri(uri)
|
||||||
uri = uri.to_s
|
uri = URINormalizer.normalize_suffix(uri.to_s)
|
||||||
uri = "#{uri}/" unless %r{/$}.match?(uri)
|
|
||||||
require_relative "../vendored_uri"
|
require_relative "../vendored_uri"
|
||||||
uri = Bundler::URI(uri)
|
uri = Bundler::URI(uri)
|
||||||
raise ArgumentError, "The source must be an absolute URI. For example:\n" \
|
raise ArgumentError, "The source must be an absolute URI. For example:\n" \
|
||||||
|
23
lib/bundler/uri_normalizer.rb
Normal file
23
lib/bundler/uri_normalizer.rb
Normal 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
|
@ -140,6 +140,24 @@ RSpec.describe "bundle lock" do
|
|||||||
expect(read_lockfile).to eq(@lockfile)
|
expect(read_lockfile).to eq(@lockfile)
|
||||||
end
|
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
|
it "errors when updating a missing specific gems using --update" do
|
||||||
lockfile @lockfile
|
lockfile @lockfile
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user