bundler 2.2.24 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +246 -1
  3. data/README.md +1 -1
  4. data/exe/bundle +7 -8
  5. data/lib/bundler/.document +1 -0
  6. data/lib/bundler/build_metadata.rb +2 -2
  7. data/lib/bundler/cli/cache.rb +1 -1
  8. data/lib/bundler/cli/config.rb +10 -1
  9. data/lib/bundler/cli/doctor.rb +13 -4
  10. data/lib/bundler/cli/exec.rb +1 -6
  11. data/lib/bundler/cli/gem.rb +101 -11
  12. data/lib/bundler/cli/info.rb +26 -5
  13. data/lib/bundler/cli/install.rb +12 -45
  14. data/lib/bundler/cli/issue.rb +4 -3
  15. data/lib/bundler/cli/list.rb +7 -1
  16. data/lib/bundler/cli/open.rb +1 -2
  17. data/lib/bundler/cli/platform.rb +1 -1
  18. data/lib/bundler/cli/remove.rb +1 -2
  19. data/lib/bundler/cli/update.rb +9 -5
  20. data/lib/bundler/cli.rb +24 -20
  21. data/lib/bundler/compact_index_client/cache.rb +0 -9
  22. data/lib/bundler/compact_index_client/updater.rb +0 -5
  23. data/lib/bundler/compact_index_client.rb +2 -8
  24. data/lib/bundler/definition.rb +97 -161
  25. data/lib/bundler/dependency.rb +5 -7
  26. data/lib/bundler/digest.rb +71 -0
  27. data/lib/bundler/dsl.rb +32 -31
  28. data/lib/bundler/endpoint_specification.rb +21 -11
  29. data/lib/bundler/env.rb +1 -1
  30. data/lib/bundler/environment_preserver.rb +4 -1
  31. data/lib/bundler/errors.rb +19 -3
  32. data/lib/bundler/fetcher/compact_index.rb +9 -14
  33. data/lib/bundler/fetcher/index.rb +0 -26
  34. data/lib/bundler/fetcher.rb +13 -20
  35. data/lib/bundler/friendly_errors.rb +5 -30
  36. data/lib/bundler/gem_helper.rb +7 -18
  37. data/lib/bundler/injector.rb +10 -1
  38. data/lib/bundler/installer/gem_installer.rb +4 -22
  39. data/lib/bundler/installer/standalone.rb +13 -8
  40. data/lib/bundler/installer.rb +1 -5
  41. data/lib/bundler/lazy_specification.rb +19 -3
  42. data/lib/bundler/lockfile_generator.rb +1 -1
  43. data/lib/bundler/lockfile_parser.rb +11 -12
  44. data/lib/bundler/man/bundle-add.1 +10 -2
  45. data/lib/bundler/man/bundle-add.1.ronn +7 -1
  46. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  47. data/lib/bundler/man/bundle-cache.1 +1 -1
  48. data/lib/bundler/man/bundle-check.1 +1 -1
  49. data/lib/bundler/man/bundle-clean.1 +1 -1
  50. data/lib/bundler/man/bundle-config.1 +5 -5
  51. data/lib/bundler/man/bundle-config.1.ronn +5 -5
  52. data/lib/bundler/man/bundle-doctor.1 +1 -1
  53. data/lib/bundler/man/bundle-exec.1 +1 -1
  54. data/lib/bundler/man/bundle-gem.1 +14 -1
  55. data/lib/bundler/man/bundle-gem.1.ronn +16 -0
  56. data/lib/bundler/man/bundle-info.1 +1 -1
  57. data/lib/bundler/man/bundle-init.1 +1 -1
  58. data/lib/bundler/man/bundle-inject.1 +1 -1
  59. data/lib/bundler/man/bundle-install.1 +2 -2
  60. data/lib/bundler/man/bundle-install.1.ronn +2 -2
  61. data/lib/bundler/man/bundle-list.1 +1 -1
  62. data/lib/bundler/man/bundle-lock.1 +1 -1
  63. data/lib/bundler/man/bundle-open.1 +1 -1
  64. data/lib/bundler/man/bundle-outdated.1 +1 -1
  65. data/lib/bundler/man/bundle-platform.1 +1 -1
  66. data/lib/bundler/man/bundle-pristine.1 +1 -1
  67. data/lib/bundler/man/bundle-remove.1 +1 -1
  68. data/lib/bundler/man/bundle-show.1 +1 -1
  69. data/lib/bundler/man/bundle-update.1 +2 -2
  70. data/lib/bundler/man/bundle-update.1.ronn +2 -1
  71. data/lib/bundler/man/bundle-viz.1 +1 -1
  72. data/lib/bundler/man/bundle.1 +1 -1
  73. data/lib/bundler/man/gemfile.5 +28 -2
  74. data/lib/bundler/man/gemfile.5.ronn +9 -1
  75. data/lib/bundler/plugin/api/source.rb +1 -0
  76. data/lib/bundler/plugin/installer.rb +3 -1
  77. data/lib/bundler/plugin.rb +23 -6
  78. data/lib/bundler/process_lock.rb +1 -1
  79. data/lib/bundler/remote_specification.rb +7 -0
  80. data/lib/bundler/resolver/spec_group.rb +1 -1
  81. data/lib/bundler/resolver.rb +38 -47
  82. data/lib/bundler/ruby_version.rb +1 -1
  83. data/lib/bundler/rubygems_ext.rb +19 -10
  84. data/lib/bundler/rubygems_gem_installer.rb +25 -5
  85. data/lib/bundler/rubygems_integration.rb +40 -70
  86. data/lib/bundler/runtime.rb +17 -8
  87. data/lib/bundler/self_manager.rb +168 -0
  88. data/lib/bundler/settings.rb +15 -2
  89. data/lib/bundler/setup.rb +2 -2
  90. data/lib/bundler/shared_helpers.rb +4 -19
  91. data/lib/bundler/source/git/git_proxy.rb +8 -6
  92. data/lib/bundler/source/git.rb +22 -4
  93. data/lib/bundler/source/metadata.rb +1 -1
  94. data/lib/bundler/source/rubygems.rb +70 -81
  95. data/lib/bundler/source/rubygems_aggregate.rb +4 -0
  96. data/lib/bundler/source.rb +4 -0
  97. data/lib/bundler/source_list.rb +22 -31
  98. data/lib/bundler/spec_set.rb +14 -36
  99. data/lib/bundler/templates/Executable.bundler +7 -7
  100. data/lib/bundler/templates/Gemfile +0 -2
  101. data/lib/bundler/templates/gems.rb +0 -3
  102. data/lib/bundler/templates/newgem/Gemfile.tt +5 -2
  103. data/lib/bundler/templates/newgem/Rakefile.tt +15 -2
  104. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +13 -2
  105. data/lib/bundler/templates/newgem/newgem.gemspec.tt +17 -15
  106. data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  107. data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  108. data/lib/bundler/templates/newgem/test/minitest/{newgem_test.rb.tt → test_newgem.rb.tt} +1 -1
  109. data/lib/bundler/ui/shell.rb +1 -1
  110. data/lib/bundler/vendor/.document +1 -0
  111. data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  112. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +19 -21
  113. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  114. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +57 -0
  115. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +39 -74
  116. data/lib/bundler/vendor/fileutils/LICENSE.txt +22 -0
  117. data/lib/bundler/vendor/molinillo/LICENSE +9 -0
  118. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  119. data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  120. data/lib/bundler/vendor/thor/LICENSE.md +20 -0
  121. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +6 -6
  122. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -2
  123. data/lib/bundler/vendor/thor/lib/thor/actions.rb +6 -2
  124. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +6 -0
  125. data/lib/bundler/vendor/thor/lib/thor/error.rb +9 -4
  126. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +19 -1
  127. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +22 -4
  128. data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  129. data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
  130. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  131. data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  132. data/lib/bundler/vendor/tsort/lib/tsort.rb +453 -0
  133. data/lib/bundler/vendor/uri/LICENSE.txt +22 -0
  134. data/lib/bundler/vendor/uri/lib/uri/common.rb +17 -80
  135. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +0 -1
  136. data/lib/bundler/vendor/uri/lib/uri/generic.rb +5 -6
  137. data/lib/bundler/vendor/uri/lib/uri/http.rb +0 -1
  138. data/lib/bundler/vendor/uri/lib/uri/https.rb +0 -1
  139. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +1 -1
  140. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +0 -1
  141. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +1 -14
  142. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +1 -12
  143. data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  144. data/lib/bundler/vendor/uri/lib/uri/ws.rb +84 -0
  145. data/lib/bundler/vendor/uri/lib/uri/wss.rb +22 -0
  146. data/lib/bundler/vendor/uri/lib/uri.rb +0 -1
  147. data/lib/bundler/vendored_tsort.rb +4 -0
  148. data/lib/bundler/version.rb +1 -1
  149. data/lib/bundler/worker.rb +19 -4
  150. data/lib/bundler.rb +23 -26
  151. metadata +25 -10
  152. data/lib/bundler/gemdeps.rb +0 -29
  153. data/lib/bundler/psyched_yaml.rb +0 -22
  154. data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +0 -66
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ #
5
+ # This class handles installing and switching to the version of bundler needed
6
+ # by an application.
7
+ #
8
+ class SelfManager
9
+ def restart_with_locked_bundler_if_needed
10
+ return unless needs_switching? && installed?
11
+
12
+ restart_with(lockfile_version)
13
+ end
14
+
15
+ def install_locked_bundler_and_restart_with_it_if_needed
16
+ return unless needs_switching?
17
+
18
+ Bundler.ui.info \
19
+ "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \
20
+ "Installing Bundler #{lockfile_version} and restarting using that version."
21
+
22
+ install_and_restart_with(lockfile_version)
23
+ end
24
+
25
+ def update_bundler_and_restart_with_it_if_needed(target)
26
+ return unless autoswitching_applies?
27
+
28
+ spec = resolve_update_version_from(target)
29
+ return unless spec
30
+
31
+ version = spec.version
32
+
33
+ Bundler.ui.info "Updating bundler to #{version}."
34
+
35
+ install(spec)
36
+
37
+ restart_with(version)
38
+ end
39
+
40
+ private
41
+
42
+ def install_and_restart_with(version)
43
+ requirement = Gem::Requirement.new(version)
44
+ spec = find_latest_matching_spec(requirement)
45
+
46
+ if spec.nil?
47
+ Bundler.ui.warn "Your lockfile is locked to a version of bundler (#{lockfile_version}) that doesn't exist at https://rubygems.org/. Going on using #{current_version}"
48
+ return
49
+ end
50
+
51
+ install(spec)
52
+ rescue StandardError => e
53
+ Bundler.ui.trace e
54
+ Bundler.ui.warn "There was an error installing the locked bundler version (#{lockfile_version}), rerun with the `--verbose` flag for more details. Going on using bundler #{current_version}."
55
+ else
56
+ restart_with(version)
57
+ end
58
+
59
+ def install(spec)
60
+ spec.source.install(spec)
61
+ end
62
+
63
+ def restart_with(version)
64
+ configured_gem_home = ENV["GEM_HOME"]
65
+ configured_gem_path = ENV["GEM_PATH"]
66
+
67
+ cmd = [$PROGRAM_NAME, *ARGV]
68
+ cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
69
+
70
+ Bundler.with_original_env do
71
+ Kernel.exec(
72
+ { "GEM_HOME" => configured_gem_home, "GEM_PATH" => configured_gem_path, "BUNDLER_VERSION" => version.to_s },
73
+ *cmd
74
+ )
75
+ end
76
+ end
77
+
78
+ def needs_switching?
79
+ autoswitching_applies? &&
80
+ released?(lockfile_version) &&
81
+ !running?(lockfile_version) &&
82
+ !updating?
83
+ end
84
+
85
+ def autoswitching_applies?
86
+ ENV["BUNDLER_VERSION"].nil? &&
87
+ Bundler.rubygems.supports_bundler_trampolining? &&
88
+ SharedHelpers.in_bundle? &&
89
+ lockfile_version
90
+ end
91
+
92
+ def resolve_update_version_from(target)
93
+ requirement = Gem::Requirement.new(target)
94
+ update_candidate = find_latest_matching_spec(requirement)
95
+
96
+ if update_candidate.nil?
97
+ raise InvalidOption, "The `bundle update --bundler` target version (#{target}) does not exist"
98
+ end
99
+
100
+ resolved_version = update_candidate.version
101
+ needs_update = requirement.specific? ? !running?(resolved_version) : running_older_than?(resolved_version)
102
+
103
+ return unless needs_update
104
+
105
+ update_candidate
106
+ end
107
+
108
+ def local_specs
109
+ @local_specs ||= Bundler::Source::Rubygems.new("allow_local" => true).specs.select {|spec| spec.name == "bundler" }
110
+ end
111
+
112
+ def remote_specs
113
+ @remote_specs ||= begin
114
+ source = Bundler::Source::Rubygems.new("remotes" => "https://rubygems.org")
115
+ source.remote!
116
+ source.add_dependency_names("bundler")
117
+ source.specs
118
+ end
119
+ end
120
+
121
+ def find_latest_matching_spec(requirement)
122
+ local_result = find_latest_matching_spec_from_collection(local_specs, requirement)
123
+ return local_result if local_result && requirement.specific?
124
+
125
+ remote_result = find_latest_matching_spec_from_collection(remote_specs, requirement)
126
+ return remote_result if local_result.nil?
127
+
128
+ [local_result, remote_result].max
129
+ end
130
+
131
+ def find_latest_matching_spec_from_collection(specs, requirement)
132
+ specs.sort.reverse_each.find {|spec| requirement.satisfied_by?(spec.version) }
133
+ end
134
+
135
+ def running?(version)
136
+ version == current_version
137
+ end
138
+
139
+ def running_older_than?(version)
140
+ current_version < version
141
+ end
142
+
143
+ def released?(version)
144
+ !version.to_s.end_with?(".dev")
145
+ end
146
+
147
+ def updating?
148
+ "update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") }
149
+ end
150
+
151
+ def installed?
152
+ Bundler.configure
153
+
154
+ Bundler.rubygems.find_bundler(lockfile_version.to_s)
155
+ end
156
+
157
+ def current_version
158
+ @current_version ||= Gem::Version.new(Bundler::VERSION)
159
+ end
160
+
161
+ def lockfile_version
162
+ return @lockfile_version if defined?(@lockfile_version)
163
+
164
+ parsed_version = Bundler::LockfileParser.bundled_with
165
+ @lockfile_version = parsed_version ? Gem::Version.new(parsed_version) : nil
166
+ end
167
+ end
168
+ end
@@ -219,6 +219,7 @@ module Bundler
219
219
  def path
220
220
  configs.each do |_level, settings|
221
221
  path = value_for("path", settings)
222
+ path = "vendor/bundle" if value_for("deployment", settings) && path.nil?
222
223
  path_system = value_for("path.system", settings)
223
224
  disabled_shared_gems = value_for("disable_shared_gems", settings)
224
225
  next if path.nil? && path_system.nil? && disabled_shared_gems.nil?
@@ -366,7 +367,7 @@ module Bundler
366
367
 
367
368
  def to_array(value)
368
369
  return [] unless value
369
- value.split(":").map(&:to_sym)
370
+ value.tr(" ", ":").split(":").map(&:to_sym)
370
371
  end
371
372
 
372
373
  def array_to_s(array)
@@ -419,7 +420,15 @@ module Bundler
419
420
  elsif is_credential(key)
420
421
  "[REDACTED]"
421
422
  elsif is_userinfo(converted)
422
- converted.gsub(/:.*$/, ":[REDACTED]")
423
+ username, pass = converted.split(":", 2)
424
+
425
+ if pass == "x-oauth-basic"
426
+ username = "[REDACTED]"
427
+ else
428
+ pass = "[REDACTED]"
429
+ end
430
+
431
+ [username, pass].join(":")
423
432
  else
424
433
  converted
425
434
  end
@@ -428,6 +437,10 @@ module Bundler
428
437
  def global_config_file
429
438
  if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
430
439
  Pathname.new(ENV["BUNDLE_CONFIG"])
440
+ elsif ENV["BUNDLE_USER_CONFIG"] && !ENV["BUNDLE_USER_CONFIG"].empty?
441
+ Pathname.new(ENV["BUNDLE_USER_CONFIG"])
442
+ elsif ENV["BUNDLE_USER_HOME"] && !ENV["BUNDLE_USER_HOME"].empty?
443
+ Pathname.new(ENV["BUNDLE_USER_HOME"]).join("config")
431
444
  elsif Bundler.rubygems.user_home && !Bundler.rubygems.user_home.empty?
432
445
  Pathname.new(Bundler.rubygems.user_home).join(".bundle/config")
433
446
  end
data/lib/bundler/setup.rb CHANGED
@@ -9,10 +9,10 @@ if Bundler::SharedHelpers.in_bundle?
9
9
  begin
10
10
  Bundler.ui.silence { Bundler.setup }
11
11
  rescue Bundler::BundlerError => e
12
- Bundler.ui.warn "\e[31m#{e.message}\e[0m"
12
+ Bundler.ui.error e.message
13
13
  Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"]
14
14
  if e.is_a?(Bundler::GemNotFound)
15
- Bundler.ui.warn "\e[33mRun `bundle install` to install missing gems.\e[0m"
15
+ Bundler.ui.warn "Run `bundle install` to install missing gems."
16
16
  end
17
17
  exit e.status_code
18
18
  end
@@ -109,7 +109,7 @@ module Bundler
109
109
  raise VirtualProtocolError.new
110
110
  rescue Errno::ENOSPC
111
111
  raise NoSpaceOnDeviceError.new(path, action)
112
- rescue *[const_get_safely(:ENOTSUP, Errno)].compact
112
+ rescue Errno::ENOTSUP
113
113
  raise OperationNotSupportedError.new(path, action)
114
114
  rescue Errno::EEXIST, Errno::ENOENT
115
115
  raise
@@ -117,13 +117,6 @@ module Bundler
117
117
  raise GenericSystemCallError.new(e, "There was an error accessing `#{path}`.")
118
118
  end
119
119
 
120
- def const_get_safely(constant_name, namespace)
121
- const_in_namespace = namespace.constants.include?(constant_name.to_s) ||
122
- namespace.constants.include?(constant_name.to_sym)
123
- return nil unless const_in_namespace
124
- namespace.const_get(constant_name)
125
- end
126
-
127
120
  def major_deprecation(major_version, message, print_caller_location: false)
128
121
  if print_caller_location
129
122
  caller_location = caller_locations(2, 2).first
@@ -152,13 +145,6 @@ module Bundler
152
145
  Bundler.ui.warn message
153
146
  end
154
147
 
155
- def trap(signal, override = false, &block)
156
- prior = Signal.trap(signal) do
157
- block.call
158
- prior.call unless override
159
- end
160
- end
161
-
162
148
  def ensure_same_dependencies(spec, old_deps, new_deps)
163
149
  new_deps = new_deps.reject {|d| d.type == :development }
164
150
  old_deps = old_deps.reject {|d| d.type == :development }
@@ -253,7 +239,7 @@ module Bundler
253
239
  current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if RUBY_VERSION < "2.7" }
254
240
 
255
241
  until !File.directory?(current) || current == previous
256
- if ENV["BUNDLE_SPEC_RUN"]
242
+ if ENV["BUNDLER_SPEC_RUN"]
257
243
  # avoid stepping above the tmp directory when testing
258
244
  gemspec = if ENV["GEM_COMMAND"]
259
245
  # for Ruby Core
@@ -327,12 +313,11 @@ module Bundler
327
313
  end
328
314
 
329
315
  def clean_load_path
330
- bundler_lib = bundler_ruby_lib
331
-
332
316
  loaded_gem_paths = Bundler.rubygems.loaded_gem_paths
333
317
 
334
318
  $LOAD_PATH.reject! do |p|
335
- next if resolve_path(p).start_with?(bundler_lib)
319
+ resolved_path = resolve_path(p)
320
+ next if $LOADED_FEATURES.any? {|lf| lf.start_with?(resolved_path) }
336
321
  loaded_gem_paths.delete(p)
337
322
  end
338
323
  $LOAD_PATH.uniq!
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "shellwords"
4
-
5
3
  module Bundler
6
4
  class Source
7
5
  class Git
@@ -58,7 +56,6 @@ module Bundler
58
56
  @ref = ref
59
57
  @revision = revision
60
58
  @git = git
61
- raise GitNotInstalledError.new if allow? && !Bundler.git_present?
62
59
  end
63
60
 
64
61
  def revision
@@ -98,12 +95,12 @@ module Bundler
98
95
  SharedHelpers.filesystem_access(path.dirname) do |p|
99
96
  FileUtils.mkdir_p(p)
100
97
  end
101
- git_retry "clone", configured_uri, path.to_s, "--bare", "--no-hardlinks", "--quiet"
98
+ git_retry "clone", "--bare", "--no-hardlinks", "--quiet", "--", configured_uri, path.to_s
102
99
  return unless extra_ref
103
100
  end
104
101
 
105
102
  with_path do
106
- git_retry(*["fetch", "--force", "--quiet", "--tags", configured_uri, "refs/heads/*:refs/heads/*", extra_ref].compact, :dir => path)
103
+ git_retry(*["fetch", "--force", "--quiet", "--tags", "--", configured_uri, "refs/heads/*:refs/heads/*", extra_ref].compact, :dir => path)
107
104
  end
108
105
  end
109
106
 
@@ -210,7 +207,11 @@ module Bundler
210
207
  end
211
208
 
212
209
  def allow?
213
- @git ? @git.allow_git_ops? : true
210
+ allowed = @git ? @git.allow_git_ops? : true
211
+
212
+ raise GitNotInstalledError.new if allowed && !Bundler.git_present?
213
+
214
+ allowed
214
215
  end
215
216
 
216
217
  def with_path(&blk)
@@ -224,6 +225,7 @@ module Bundler
224
225
  end
225
226
 
226
227
  def check_allowed(command)
228
+ require "shellwords"
227
229
  command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri)
228
230
  raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
229
231
  command_with_no_credentials
@@ -42,7 +42,7 @@ module Bundler
42
42
  %w[ref branch tag submodules].each do |opt|
43
43
  out << " #{opt}: #{options[opt]}\n" if options[opt]
44
44
  end
45
- out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
45
+ out << " glob: #{@glob}\n" unless default_glob?
46
46
  out << " specs:\n"
47
47
  end
48
48
 
@@ -75,12 +75,20 @@ module Bundler
75
75
  git_proxy.branch
76
76
  end
77
77
 
78
- rev = " (at #{at}@#{shortref_for_display(revision)})"
78
+ rev = "at #{at}@#{shortref_for_display(revision)}"
79
79
  rescue GitError
80
80
  ""
81
81
  end
82
82
 
83
- "#{@safe_uri}#{rev}"
83
+ specifiers = [rev, glob_for_display].compact
84
+ suffix =
85
+ if specifiers.any?
86
+ " (#{specifiers.join(", ")})"
87
+ else
88
+ ""
89
+ end
90
+
91
+ "#{@safe_uri}#{suffix}"
84
92
  end
85
93
 
86
94
  def name
@@ -282,6 +290,14 @@ module Bundler
282
290
  ref[0..11]
283
291
  end
284
292
 
293
+ def glob_for_display
294
+ default_glob? ? nil : "glob: #{@glob}"
295
+ end
296
+
297
+ def default_glob?
298
+ @glob == DEFAULT_GLOB
299
+ end
300
+
285
301
  def uri_hash
286
302
  if uri =~ %r{^\w+://(\w+@)?}
287
303
  # Downcase the domain component of the URI
@@ -291,7 +307,9 @@ module Bundler
291
307
  # If there is no URI scheme, assume it is an ssh/git URI
292
308
  input = uri
293
309
  end
294
- SharedHelpers.digest(:SHA1).hexdigest(input)
310
+ # We use SHA1 here for historical reason and to preserve backward compatibility.
311
+ # But a transition to a simpler mangling algorithm would be welcome.
312
+ Bundler::Digest.sha1(input)
295
313
  end
296
314
 
297
315
  def cached_revision
@@ -25,7 +25,7 @@ module Bundler
25
25
  s.loaded_from = File.expand_path("..", __FILE__)
26
26
  end
27
27
 
28
- if local_spec = Bundler.rubygems.find_name("bundler").find {|s| s.version.to_s == VERSION }
28
+ if local_spec = Bundler.rubygems.find_bundler(VERSION)
29
29
  idx << local_spec
30
30
  end
31
31
 
@@ -29,6 +29,7 @@ module Bundler
29
29
  def local_only!
30
30
  @specs = nil
31
31
  @allow_local = true
32
+ @allow_cached = false
32
33
  @allow_remote = false
33
34
  end
34
35
 
@@ -50,6 +51,7 @@ module Bundler
50
51
  return if @allow_cached
51
52
 
52
53
  @specs = nil
54
+ @allow_local = true
53
55
  @allow_cached = true
54
56
  end
55
57
 
@@ -71,6 +73,10 @@ module Bundler
71
73
  @remotes.size > 1
72
74
  end
73
75
 
76
+ def no_remotes?
77
+ @remotes.size == 0
78
+ end
79
+
74
80
  def can_lock?(spec)
75
81
  return super unless multiple_remotes?
76
82
  include?(spec.source)
@@ -95,12 +101,27 @@ module Bundler
95
101
  def to_s
96
102
  if remotes.empty?
97
103
  "locally installed gems"
98
- else
99
- remote_names = remotes.map(&:to_s).join(", ")
104
+ elsif @allow_remote && @allow_cached && @allow_local
105
+ "rubygems repository #{remote_names}, cached gems or installed locally"
106
+ elsif @allow_remote && @allow_local
100
107
  "rubygems repository #{remote_names} or installed locally"
108
+ elsif @allow_remote
109
+ "rubygems repository #{remote_names}"
110
+ elsif @allow_cached && @allow_local
111
+ "cached gems or installed locally"
112
+ else
113
+ "locally installed gems"
114
+ end
115
+ end
116
+
117
+ def identifier
118
+ if remotes.empty?
119
+ "locally installed gems"
120
+ else
121
+ "rubygems repository #{remote_names}"
101
122
  end
102
123
  end
103
- alias_method :name, :to_s
124
+ alias_method :name, :identifier
104
125
 
105
126
  def specs
106
127
  @specs ||= begin
@@ -118,7 +139,7 @@ module Bundler
118
139
  force = opts[:force]
119
140
  ensure_builtin_gems_cached = opts[:ensure_builtin_gems_cached]
120
141
 
121
- if ensure_builtin_gems_cached && builtin_gem?(spec)
142
+ if ensure_builtin_gems_cached && spec.default_gem?
122
143
  if !cached_path(spec)
123
144
  cached_built_in_gem(spec) unless spec.remote
124
145
  force = true
@@ -127,7 +148,7 @@ module Bundler
127
148
  end
128
149
  end
129
150
 
130
- if (installed?(spec) || Plugin.installed?(spec.name)) && !force
151
+ if installed?(spec) && !force
131
152
  print_using_message "Using #{version_message(spec)}"
132
153
  return nil # no post-install message
133
154
  end
@@ -145,7 +166,7 @@ module Bundler
145
166
  begin
146
167
  s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"])
147
168
  spec.__swap__(s)
148
- rescue StandardError
169
+ rescue Gem::Package::FormatError
149
170
  Bundler.rm_rf(path)
150
171
  raise
151
172
  end
@@ -157,6 +178,7 @@ module Bundler
157
178
  Bundler.ui.confirm message
158
179
 
159
180
  path = cached_gem(spec)
181
+ raise GemNotFound, "Could not find #{spec.file_name} for installation" unless path
160
182
  if requires_sudo?
161
183
  install_path = Bundler.tmp(spec.full_name)
162
184
  bin_path = install_path.join("bin")
@@ -216,12 +238,8 @@ module Bundler
216
238
  end
217
239
 
218
240
  def cache(spec, custom_path = nil)
219
- if builtin_gem?(spec)
220
- cached_path = cached_built_in_gem(spec)
221
- else
222
- cached_path = cached_gem(spec)
223
- end
224
- raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path
241
+ cached_path = cached_gem(spec)
242
+ raise GemNotFound, "Missing gem file '#{spec.file_name}'." unless cached_path
225
243
  return if File.dirname(cached_path) == Bundler.app_cache.to_s
226
244
  Bundler.ui.info " * #{File.basename(cached_path)}"
227
245
  FileUtils.cp(cached_path, Bundler.app_cache(custom_path))
@@ -248,10 +266,6 @@ module Bundler
248
266
  @remotes.unshift(uri) unless @remotes.include?(uri)
249
267
  end
250
268
 
251
- def equivalent_remotes?(other_remotes)
252
- other_remotes.map(&method(:remove_auth)) == @remotes.map(&method(:remove_auth))
253
- end
254
-
255
269
  def spec_names
256
270
  if @allow_remote && dependency_api_available?
257
271
  remote_specs.spec_names
@@ -315,8 +329,16 @@ module Bundler
315
329
 
316
330
  protected
317
331
 
332
+ def remote_names
333
+ remotes.map(&:to_s).join(", ")
334
+ end
335
+
318
336
  def credless_remotes
319
- remotes.map(&method(:suppress_configured_credentials))
337
+ if Bundler.settings[:allow_deployment_source_credential_changes]
338
+ remotes.map(&method(:remove_auth))
339
+ else
340
+ remotes.map(&method(:suppress_configured_credentials))
341
+ end
320
342
  end
321
343
 
322
344
  def remotes_for_spec(spec)
@@ -331,14 +353,17 @@ module Bundler
331
353
  end
332
354
 
333
355
  def cached_gem(spec)
334
- cached_gem = cached_path(spec)
335
- unless cached_gem
336
- raise Bundler::GemNotFound, "Could not find #{spec.file_name} for installation"
356
+ if spec.default_gem?
357
+ cached_built_in_gem(spec)
358
+ else
359
+ cached_path(spec)
337
360
  end
338
- cached_gem
339
361
  end
340
362
 
341
363
  def cached_path(spec)
364
+ global_cache_path = download_cache_path(spec)
365
+ @caches << global_cache_path if global_cache_path
366
+
342
367
  possibilities = @caches.map {|p| "#{p}/#{spec.file_name}" }
343
368
  possibilities.find {|p| File.exist?(p) }
344
369
  end
@@ -438,19 +463,26 @@ module Bundler
438
463
 
439
464
  spec.fetch_platform
440
465
 
441
- download_path = requires_sudo? ? Bundler.tmp(spec.full_name) : rubygems_dir
442
- gem_path = "#{rubygems_dir}/cache/#{spec.full_name}.gem"
466
+ cache_path = download_cache_path(spec) || default_cache_path_for(rubygems_dir)
467
+ gem_path = "#{cache_path}/#{spec.file_name}"
468
+
469
+ if requires_sudo?
470
+ download_path = Bundler.tmp(spec.full_name)
471
+ download_cache_path = default_cache_path_for(download_path)
472
+ else
473
+ download_cache_path = cache_path
474
+ end
443
475
 
444
- SharedHelpers.filesystem_access("#{download_path}/cache") do |p|
476
+ SharedHelpers.filesystem_access(download_cache_path) do |p|
445
477
  FileUtils.mkdir_p(p)
446
478
  end
447
- download_gem(spec, download_path)
479
+ download_gem(spec, download_cache_path)
448
480
 
449
481
  if requires_sudo?
450
- SharedHelpers.filesystem_access("#{rubygems_dir}/cache") do |p|
482
+ SharedHelpers.filesystem_access(cache_path) do |p|
451
483
  Bundler.mkdir_p(p)
452
484
  end
453
- Bundler.sudo "mv #{download_path}/cache/#{spec.full_name}.gem #{gem_path}"
485
+ Bundler.sudo "mv #{download_cache_path}/#{spec.file_name} #{gem_path}"
454
486
  end
455
487
 
456
488
  gem_path
@@ -458,16 +490,8 @@ module Bundler
458
490
  Bundler.rm_rf(download_path) if requires_sudo?
459
491
  end
460
492
 
461
- def builtin_gem?(spec)
462
- # Ruby 2.1, where all included gems have this summary
463
- return true if spec.summary =~ /is bundled with Ruby/
464
-
465
- # Ruby 2.0, where gemspecs are stored in specifications/default/
466
- spec.loaded_from && spec.loaded_from.include?("specifications/default/")
467
- end
468
-
469
493
  def installed?(spec)
470
- installed_specs[spec].any?
494
+ installed_specs[spec].any? && !spec.deleted_gem?
471
495
  end
472
496
 
473
497
  def requires_sudo?
@@ -478,6 +502,10 @@ module Bundler
478
502
  Bundler.rubygems.gem_dir
479
503
  end
480
504
 
505
+ def default_cache_path_for(dir)
506
+ "#{dir}/cache"
507
+ end
508
+
481
509
  def cache_path
482
510
  Bundler.app_cache
483
511
  end
@@ -490,52 +518,13 @@ module Bundler
490
518
  # @param [Specification] spec
491
519
  # the spec we want to download or retrieve from the cache.
492
520
  #
493
- # @param [String] download_path
521
+ # @param [String] download_cache_path
494
522
  # the local directory the .gem will end up in.
495
523
  #
496
- def download_gem(spec, download_path)
497
- local_path = File.join(download_path, "cache/#{spec.full_name}.gem")
498
-
499
- if (cache_path = download_cache_path(spec)) && cache_path.file?
500
- SharedHelpers.filesystem_access(local_path) do
501
- FileUtils.cp(cache_path, local_path)
502
- end
503
- else
504
- uri = spec.remote.uri
505
- Bundler.ui.confirm("Fetching #{version_message(spec)}")
506
- rubygems_local_path = Bundler.rubygems.download_gem(spec, uri, download_path)
507
-
508
- # older rubygems return varying file:// variants depending on version
509
- rubygems_local_path = rubygems_local_path.gsub(/\Afile:/, "") unless Bundler.rubygems.provides?(">= 3.2.0.rc.2")
510
- rubygems_local_path = rubygems_local_path.gsub(%r{\A//}, "") if Bundler.rubygems.provides?("< 3.1.0")
511
-
512
- if rubygems_local_path != local_path
513
- SharedHelpers.filesystem_access(local_path) do
514
- FileUtils.mv(rubygems_local_path, local_path)
515
- end
516
- end
517
- cache_globally(spec, local_path)
518
- end
519
- end
520
-
521
- # Checks if the requested spec exists in the global cache. If it does
522
- # not, we create the relevant global cache subdirectory if it does not
523
- # exist and copy the spec from the local cache to the global cache.
524
- #
525
- # @param [Specification] spec
526
- # the spec we want to copy to the global cache.
527
- #
528
- # @param [String] local_cache_path
529
- # the local directory from which we want to copy the .gem.
530
- #
531
- def cache_globally(spec, local_cache_path)
532
- return unless cache_path = download_cache_path(spec)
533
- return if cache_path.exist?
534
-
535
- SharedHelpers.filesystem_access(cache_path.dirname, &:mkpath)
536
- SharedHelpers.filesystem_access(cache_path) do
537
- FileUtils.cp(local_cache_path, cache_path)
538
- end
524
+ def download_gem(spec, download_cache_path)
525
+ uri = spec.remote.uri
526
+ Bundler.ui.confirm("Fetching #{version_message(spec)}")
527
+ Bundler.rubygems.download_gem(spec, uri, download_cache_path)
539
528
  end
540
529
 
541
530
  # Returns the global cache path of the calling Rubygems::Source object.
@@ -554,7 +543,7 @@ module Bundler
554
543
  return unless remote = spec.remote
555
544
  return unless cache_slug = remote.cache_slug
556
545
 
557
- Bundler.user_cache.join("gems", cache_slug, spec.file_name)
546
+ Bundler.user_cache.join("gems", cache_slug)
558
547
  end
559
548
 
560
549
  def extension_cache_slug(spec)