tap: fix arguments.

- Use Ruby attribute arguments.
- Fix use of `full_clone` in `cmd/tap` to be on by default.
- Remove unnecessary argument in test.
This commit is contained in:
Mike McQuaid 2020-02-05 20:22:21 +00:00
parent 72303fb9bb
commit a915114ea7
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 13 additions and 26 deletions

View File

@ -56,7 +56,6 @@ module Homebrew
begin begin
tap.install clone_target: ARGV.named.second, tap.install clone_target: ARGV.named.second,
force_auto_update: force_auto_update?, force_auto_update: force_auto_update?,
full_clone: full_clone?,
quiet: Homebrew.args.quiet? quiet: Homebrew.args.quiet?
rescue TapRemoteMismatchError => e rescue TapRemoteMismatchError => e
odie e odie e
@ -66,10 +65,6 @@ module Homebrew
end end
end end
def full_clone?
args.full? || ARGV.homebrew_developer?
end
def force_auto_update? def force_auto_update?
# if no relevant flag is present, return nil, meaning "no change" # if no relevant flag is present, return nil, meaning "no change"
true if args.force_auto_update? true if args.force_auto_update?

View File

@ -224,32 +224,24 @@ class Tap
# Install this {Tap}. # Install this {Tap}.
# #
# @param options [Hash] # @param clone_target [String] If passed, it will be used as the clone remote.
# @option options [String] :clone_target If passed, it will be used as the clone remote. # @param force_auto_update [Boolean, nil] If present, whether to override the
# @option options [Boolean, nil] :force_auto_update If present, whether to override the
# logic that skips non-GitHub repositories during auto-updates. # logic that skips non-GitHub repositories during auto-updates.
# @option options [Boolean] :full_clone If set as true, full clone will be used. # @param full_clone [Boolean] If set as true, full clone will be used. If unset/nil, means "no change".
# @option options [Boolean] :quiet If set, suppress all output. # @param quiet [Boolean] If set, suppress all output.
def install(options = {}) def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
require "descriptions" require "descriptions"
full_clone = options.fetch(:full_clone, true)
quiet = options.fetch(:quiet, false)
requested_remote = options[:clone_target] || default_remote
# if :force_auto_update is unset, use nil, meaning "no change"
force_auto_update = options.fetch(:force_auto_update, nil)
if official? && DEPRECATED_OFFICIAL_TAPS.include?(repo) if official? && DEPRECATED_OFFICIAL_TAPS.include?(repo)
odie "#{name} was deprecated. This tap is now empty as all its formulae were migrated." odie "#{name} was deprecated. This tap is now empty as all its formulae were migrated."
elsif user == "caskroom" elsif user == "caskroom"
odie "#{name} was moved. Tap homebrew/cask-#{repo} instead." odie "#{name} was moved. Tap homebrew/cask-#{repo} instead."
end end
if installed? requested_remote = clone_target || default_remote
if options[:clone_target] && requested_remote != remote
raise TapRemoteMismatchError.new(name, @remote, requested_remote)
end
if installed?
raise TapRemoteMismatchError.new(name, @remote, requested_remote) if clone_target && requested_remote != remote
raise TapAlreadyTappedError, name if force_auto_update.nil? raise TapAlreadyTappedError, name if force_auto_update.nil?
end end
@ -302,7 +294,7 @@ class Tap
.update_from_formula_names!(formula_names) .update_from_formula_names!(formula_names)
end end
return if options[:clone_target] return if clone_target
return unless private? return unless private?
return if quiet return if quiet
@ -647,13 +639,13 @@ class CoreTap < Tap
safe_system HOMEBREW_BREW_FILE, "tap", instance.name safe_system HOMEBREW_BREW_FILE, "tap", instance.name
end end
def install(options = {}) def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
if HOMEBREW_CORE_GIT_REMOTE != default_remote if HOMEBREW_CORE_GIT_REMOTE != default_remote
puts "HOMEBREW_CORE_GIT_REMOTE set: using #{HOMEBREW_CORE_GIT_REMOTE} " \ puts "HOMEBREW_CORE_GIT_REMOTE set: using #{HOMEBREW_CORE_GIT_REMOTE} " \
"for Homebrew/core Git remote URL." "for Homebrew/core Git remote URL."
options[:clone_target] ||= HOMEBREW_CORE_GIT_REMOTE clone_target ||= HOMEBREW_CORE_GIT_REMOTE
end end
super(options) super(full_clone: full_clone, quiet: quiet, clone_target: clone_target, force_auto_update: force_auto_update)
end end
# @private # @private

View File

@ -210,7 +210,7 @@ describe Tap do
expect(already_tapped_tap).to be_installed expect(already_tapped_tap).to be_installed
wrong_remote = "#{subject.remote}-oops" wrong_remote = "#{subject.remote}-oops"
expect { expect {
already_tapped_tap.install clone_target: wrong_remote, full_clone: true already_tapped_tap.install clone_target: wrong_remote
}.to raise_error(TapRemoteMismatchError) }.to raise_error(TapRemoteMismatchError)
end end