Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 9e06edc

Browse files
Merge #7437
7437: Extra patches for 2.1.0.pre.3 r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that before releasing 2.1.0.pre.3 I found some issues when integrating the new version into rubygems. ### What is your fix for the problem, implemented in this PR? My fix is to add the patches fixing the issues I found to the upcoming release. Co-authored-by: Bundlerbot <[email protected]> Co-authored-by: David Rodríguez <[email protected]>
2 parents 27ae250 + 9891946 commit 9e06edc

39 files changed

+195
-284
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: ruby
22
dist: bionic
33
script: bin/rake spec:travis
44
before_script:
5-
- gem install rake:"~> 12.0"
6-
- bin/rake override_version
5+
- travis_retry gem install rake:"~> 12.0"
6+
- travis_retry bin/rake override_version
77
- travis_retry bin/rake spec:travis:deps
88
- bin/rake man:check
99

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 2.1.0.pre.3 (November 8, 2019)
1+
## 2.1.0.pre.3 (November 12, 2019)
22

33
Features:
44

lib/bundler/gem_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative "vendored_thor" unless defined?(Thor)
43
require_relative "../bundler"
54
require "shellwords"
65

lib/bundler/vendor/thor/lib/thor.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def command_help(shell, command_name)
175175
handle_no_command_error(meth) unless command
176176

177177
shell.say "Usage:"
178-
shell.say " #{banner(command)}"
178+
shell.say " #{banner(command).split("\n").join("\n ")}"
179179
shell.say
180180
class_options_help(shell, nil => command.options.values)
181181
if command.long_description
@@ -398,7 +398,10 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
398398
# the namespace should be displayed as arguments.
399399
#
400400
def banner(command, namespace = nil, subcommand = false)
401-
"#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
401+
$thor_runner ||= false
402+
command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
403+
"#{basename} #{formatted_usage}"
404+
end.join("\n")
402405
end
403406

404407
def baseclass #:nodoc:

lib/bundler/vendor/thor/lib/thor/actions.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Actions
1212
attr_accessor :behavior
1313

1414
def self.included(base) #:nodoc:
15+
super(base)
1516
base.extend ClassMethods
1617
end
1718

lib/bundler/vendor/thor/lib/thor/actions/directory.rb

+6-16
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Directory < EmptyDirectory #:nodoc:
5656
attr_reader :source
5757

5858
def initialize(base, source, destination = nil, config = {}, &block)
59-
@source = File.expand_path(base.find_in_source_paths(source.to_s))
59+
@source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first)
6060
@block = block
6161
super(base, destination, {:recursive => true}.merge(config))
6262
end
@@ -96,22 +96,12 @@ def execute!
9696
end
9797
end
9898

99-
if RUBY_VERSION < "2.0"
100-
def file_level_lookup(previous_lookup)
101-
File.join(previous_lookup, "{*,.[a-z]*}")
102-
end
103-
104-
def files(lookup)
105-
Dir[lookup]
106-
end
107-
else
108-
def file_level_lookup(previous_lookup)
109-
File.join(previous_lookup, "*")
110-
end
99+
def file_level_lookup(previous_lookup)
100+
File.join(previous_lookup, "*")
101+
end
111102

112-
def files(lookup)
113-
Dir.glob(lookup, File::FNM_DOTMATCH)
114-
end
103+
def files(lookup)
104+
Dir.glob(lookup, File::FNM_DOTMATCH)
115105
end
116106
end
117107
end

lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def copy_file(source, *args, &block)
2323
destination = args.first || source
2424
source = File.expand_path(find_in_source_paths(source.to_s))
2525

26-
create_file destination, nil, config do
26+
resulting_destination = create_file destination, nil, config do
2727
content = File.binread(source)
2828
content = yield(content) if block
2929
content
3030
end
3131
if config[:mode] == :preserve
3232
mode = File.stat(source).mode
33-
chmod(destination, mode, config)
33+
chmod(resulting_destination, mode, config)
3434
end
3535
end
3636

@@ -80,14 +80,14 @@ def get(source, *args, &block)
8080
config = args.last.is_a?(Hash) ? args.pop : {}
8181
destination = args.first
8282

83-
if source =~ %r{^https?\://}
83+
render = if source =~ %r{^https?\://}
8484
require "open-uri"
85+
URI.send(:open, source) { |input| input.binmode.read }
8586
else
8687
source = File.expand_path(find_in_source_paths(source.to_s))
88+
open(source) { |input| input.binmode.read }
8789
end
8890

89-
render = open(source) { |input| input.binmode.read }
90-
9191
destination ||= if block_given?
9292
block.arity == 1 ? yield(render) : yield
9393
else

lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb

+18-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ module Actions
2121
# gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
2222
# end
2323
#
24+
WARNINGS = { unchanged_no_flag: 'File unchanged! The supplied flag value not found!' }
25+
2426
def insert_into_file(destination, *args, &block)
2527
data = block_given? ? block : args.shift
26-
config = args.shift
28+
29+
config = args.shift || {}
30+
config[:after] = /\z/ unless config.key?(:before) || config.key?(:after)
31+
2732
action InjectIntoFile.new(self, destination, data, config)
2833
end
2934
alias_method :inject_into_file, :insert_into_file
@@ -45,16 +50,18 @@ def initialize(base, destination, data, config)
4550
end
4651

4752
def invoke!
48-
say_status :invoke
49-
5053
content = if @behavior == :after
5154
'\0' + replacement
5255
else
5356
replacement + '\0'
5457
end
5558

5659
if exists?
57-
replace!(/#{flag}/, content, config[:force])
60+
if replace!(/#{flag}/, content, config[:force])
61+
say_status(:invoke)
62+
else
63+
say_status(:unchanged, warning: WARNINGS[:unchanged_no_flag], color: :red)
64+
end
5865
else
5966
unless pretend?
6067
raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist"
@@ -78,7 +85,7 @@ def revoke!
7885

7986
protected
8087

81-
def say_status(behavior)
88+
def say_status(behavior, warning: nil, color: nil)
8289
status = if behavior == :invoke
8390
if flag == /\A/
8491
:prepend
@@ -87,11 +94,13 @@ def say_status(behavior)
8794
else
8895
:insert
8996
end
97+
elsif warning
98+
warning
9099
else
91100
:subtract
92101
end
93102

94-
super(status, config[:verbose])
103+
super(status, (color || config[:verbose]))
95104
end
96105

97106
# Adds the content to the file.
@@ -100,8 +109,10 @@ def replace!(regexp, string, force)
100109
return if pretend?
101110
content = File.read(destination)
102111
if force || !content.include?(replacement)
103-
content.gsub!(regexp, string)
112+
success = content.gsub!(regexp, string)
113+
104114
File.open(destination, "wb") { |file| file.write(content) }
115+
success
105116
end
106117
end
107118
end

lib/bundler/vendor/thor/lib/thor/base.rb

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require_relative "command"
22
require_relative "core_ext/hash_with_indifferent_access"
3-
require_relative "core_ext/ordered_hash"
43
require_relative "error"
54
require_relative "invocation"
65
require_relative "parser"
@@ -89,6 +88,7 @@ def initialize(args = [], local_options = {}, config = {})
8988

9089
class << self
9190
def included(base) #:nodoc:
91+
super(base)
9292
base.extend ClassMethods
9393
base.send :include, Invocation
9494
base.send :include, Shell
@@ -353,22 +353,22 @@ def group(name = nil)
353353
# Returns the commands for this Bundler::Thor class.
354354
#
355355
# ==== Returns
356-
# OrderedHash:: An ordered hash with commands names as keys and Bundler::Thor::Command
357-
# objects as values.
356+
# Hash:: An ordered hash with commands names as keys and Bundler::Thor::Command
357+
# objects as values.
358358
#
359359
def commands
360-
@commands ||= Bundler::Thor::CoreExt::OrderedHash.new
360+
@commands ||= Hash.new
361361
end
362362
alias_method :tasks, :commands
363363

364364
# Returns the commands for this Bundler::Thor class and all subclasses.
365365
#
366366
# ==== Returns
367-
# OrderedHash:: An ordered hash with commands names as keys and Bundler::Thor::Command
368-
# objects as values.
367+
# Hash:: An ordered hash with commands names as keys and Bundler::Thor::Command
368+
# objects as values.
369369
#
370370
def all_commands
371-
@all_commands ||= from_superclass(:all_commands, Bundler::Thor::CoreExt::OrderedHash.new)
371+
@all_commands ||= from_superclass(:all_commands, Hash.new)
372372
@all_commands.merge!(commands)
373373
end
374374
alias_method :all_tasks, :all_commands
@@ -502,7 +502,7 @@ def handle_argument_error(command, error, args, arity) #:nodoc:
502502
msg = "ERROR: \"#{basename} #{name}\" was called with ".dup
503503
msg << "no arguments" if args.empty?
504504
msg << "arguments " << args.inspect unless args.empty?
505-
msg << "\nUsage: #{banner(command).inspect}"
505+
msg << "\nUsage: \"#{banner(command).split("\n").join("\"\n \"")}\""
506506
raise InvocationError, msg
507507
end
508508

@@ -596,13 +596,15 @@ def find_and_refresh_command(name) #:nodoc:
596596
# Everytime someone inherits from a Bundler::Thor class, register the klass
597597
# and file into baseclass.
598598
def inherited(klass)
599+
super(klass)
599600
Bundler::Thor::Base.register_klass_file(klass)
600601
klass.instance_variable_set(:@no_commands, false)
601602
end
602603

603604
# Fire this callback whenever a method is added. Added methods are
604605
# tracked as commands by invoking the create_command method.
605606
def method_added(meth)
607+
super(meth)
606608
meth = meth.to_s
607609

608610
if meth == "initialize"

lib/bundler/vendor/thor/lib/thor/command.rb

+21-14
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,32 @@ def formatted_usage(klass, namespace = true, subcommand = false)
4949

5050
formatted ||= "".dup
5151

52-
# Add usage with required arguments
53-
formatted << if klass && !klass.arguments.empty?
54-
usage.to_s.gsub(/^#{name}/) do |match|
55-
match << " " << klass.arguments.map(&:usage).compact.join(" ")
56-
end
57-
else
58-
usage.to_s
59-
end
52+
Array(usage).map do |specific_usage|
53+
formatted_specific_usage = formatted
6054

61-
# Add required options
62-
formatted << " #{required_options}"
55+
formatted_specific_usage += required_arguments_for(klass, specific_usage)
6356

64-
# Strip and go!
65-
formatted.strip
57+
# Add required options
58+
formatted_specific_usage += " #{required_options}"
59+
60+
# Strip and go!
61+
formatted_specific_usage.strip
62+
end.join("\n")
6663
end
6764

6865
protected
6966

67+
# Add usage with required arguments
68+
def required_arguments_for(klass, usage)
69+
if klass && !klass.arguments.empty?
70+
usage.to_s.gsub(/^#{name}/) do |match|
71+
match << " " << klass.arguments.map(&:usage).compact.join(" ")
72+
end
73+
else
74+
usage.to_s
75+
end
76+
end
77+
7078
def not_debugging?(instance)
7179
!(instance.class.respond_to?(:debugging) && instance.class.debugging)
7280
end
@@ -97,8 +105,7 @@ def sans_backtrace(backtrace, caller) #:nodoc:
97105
def handle_argument_error?(instance, error, caller)
98106
not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin
99107
saned = sans_backtrace(error.backtrace, caller)
100-
# Ruby 1.9 always include the called method in the backtrace
101-
saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
108+
saned.empty? || saned.size == 1
102109
end
103110
end
104111

0 commit comments

Comments
 (0)