Add --no-force-auto-update option to brew tap

Enable this option to delete `homebrew.forceautoupdate` git config option
This commit is contained in:
xxyzz 2022-05-06 11:57:43 +08:00
parent 14ff6be6d0
commit 2e899da7c7
No known key found for this signature in database
GPG Key ID: F796163E6DCFEE9D
4 changed files with 19 additions and 10 deletions

View File

@ -311,6 +311,9 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def print_path?; end def print_path?; end
sig { returns(T.nilable(T::Boolean)) }
def force_auto_update?; end
end end
end end
end end

View File

@ -34,7 +34,7 @@ module Homebrew
switch "--shallow", switch "--shallow",
description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration.", description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration.",
replacement: false replacement: false
switch "--force-auto-update", switch "--[no-]force-auto-update",
description: "Auto-update tap even if it is not hosted on GitHub. By default, only taps "\ description: "Auto-update tap even if it is not hosted on GitHub. By default, only taps "\
"hosted on GitHub are auto-updated (for performance reasons)." "hosted on GitHub are auto-updated (for performance reasons)."
switch "--custom-remote", switch "--custom-remote",
@ -63,7 +63,7 @@ module Homebrew
tap = Tap.fetch(args.named.first) tap = Tap.fetch(args.named.first)
begin begin
tap.install clone_target: args.named.second, tap.install clone_target: args.named.second,
force_auto_update: force_auto_update?(args: args), force_auto_update: args.force_auto_update?,
custom_remote: args.custom_remote?, custom_remote: args.custom_remote?,
quiet: args.quiet? quiet: args.quiet?
rescue TapRemoteMismatchError, TapNoCustomRemoteError => e rescue TapRemoteMismatchError, TapNoCustomRemoteError => e
@ -73,9 +73,4 @@ module Homebrew
end end
end end
end end
def force_auto_update?(args:)
# if no relevant flag is present, return nil, meaning "no change"
true if args.force_auto_update?
end
end end

View File

@ -276,7 +276,11 @@ class Tap
end end
unless force_auto_update.nil? unless force_auto_update.nil?
config["forceautoupdate"] = force_auto_update if force_auto_update
config["forceautoupdate"] = force_auto_update
elsif config["forceautoupdate"] == "true"
config.delete("forceautoupdate")
end
return return
end end
@ -932,6 +936,13 @@ class TapConfig
Homebrew::Settings.write key, value.to_s, repo: tap.path Homebrew::Settings.write key, value.to_s, repo: tap.path
end end
def delete(key)
return unless tap.git?
return unless Utils::Git.available?
Homebrew::Settings.delete key, repo: tap.path
end
end end
require "extend/os/tap" require "extend/os/tap"

View File

@ -337,7 +337,7 @@ describe Tap do
it "disables forced auto-updates when false" do it "disables forced auto-updates when false" do
expect(already_tapped_tap).to be_installed expect(already_tapped_tap).to be_installed
already_tapped_tap.install force_auto_update: false already_tapped_tap.install force_auto_update: false
expect(already_tapped_tap.config["forceautoupdate"]).to eq("false") expect(already_tapped_tap.config["forceautoupdate"]).to be_nil
end end
end end
@ -453,7 +453,7 @@ describe Tap do
expect(homebrew_foo_tap.config["foo"]).to be_nil expect(homebrew_foo_tap.config["foo"]).to be_nil
homebrew_foo_tap.config["foo"] = "bar" homebrew_foo_tap.config["foo"] = "bar"
expect(homebrew_foo_tap.config["foo"]).to eq("bar") expect(homebrew_foo_tap.config["foo"]).to eq("bar")
homebrew_foo_tap.config["foo"] = nil homebrew_foo_tap.config.delete("foo")
expect(homebrew_foo_tap.config["foo"]).to be_nil expect(homebrew_foo_tap.config["foo"]).to be_nil
end end