language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
138f7de18ffaefc5586e04c501fa2fc3ea907558.json
Refactor `brew bump`: apply suggestions from code review Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
Library/Homebrew/livecheck/livecheck.rb
@@ -60,12 +60,9 @@ def livecheck_strategy_names @livecheck_strategy_names.freeze end - # Identify taps other than homebrew/core and homebrew/cask in use - # for current formulae and casks and load additional Strategy - # files them. - sig do - params(formulae_and_casks_to_check: T::Enumerable[T.any(Formula, Cask::Cask)]).void - end + # Uses `formulae_and_casks_to_check` to identify taps in use other than + # homebrew/core and homebrew/cask and loads strategies from them. + sig { params(formulae_and_casks_to_check: T::Enumerable[T.any(Formula, Cask::Cask)]).void } def load_other_tap_strategies(formulae_and_casks_to_check) other_taps = {} formulae_and_casks_to_check.each do |formula_or_cask|
true
Other
Homebrew
brew
138f7de18ffaefc5586e04c501fa2fc3ea907558.json
Refactor `brew bump`: apply suggestions from code review Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
Library/Homebrew/utils/repology.rb
@@ -21,10 +21,8 @@ def query_api(last_package_in_response = "") end def single_package_query(name) - url = %W[ - https://repology.org/tools/project-by?repo=homebrew& - name_type=srcname&target_page=api_v1_project&name=#{name} - ].join + url = "https://repology.org/tools/project-by?repo=homebrew&" \ + "name_type=srcname&target_page=api_v1_project&name=#{name}" output, _errors, _status = curl_output("--location", url.to_s) @@ -62,8 +60,8 @@ def parse_api_response(limit = nil) end def latest_version(repositories) - # The status is "unique" when the package is present only in Homebrew, so Repology - # has no way of knowing if the package is up-to-date. + # The status is "unique" when the package is present only in Homebrew, so + # Repology has no way of knowing if the package is up-to-date. is_unique = repositories.find do |repo| repo["status"] == "unique" end.present? @@ -74,7 +72,8 @@ def latest_version(repositories) repo["status"] == "newest" end - # Repology cannot identify "newest" versions for packages without a version scheme + # Repology cannot identify "newest" versions for packages without a version + # scheme return "no latest version" if latest_version.blank? latest_version["version"]
true
Other
Homebrew
brew
4fa01fc8b75d2d0530327e9c0f11aede26a150fa.json
utils/repology: use project-by tool to retrieve Formula data
Library/Homebrew/dev-cmd/bump.rb
@@ -62,7 +62,7 @@ def bump repo["repo"] == "homebrew" end - next if homebrew_repo.blank? # TODO: check if/when this ever happens + next if homebrew_repo.blank? formula = begin Formula[homebrew_repo["srcname"]]
true
Other
Homebrew
brew
4fa01fc8b75d2d0530327e9c0f11aede26a150fa.json
utils/repology: use project-by tool to retrieve Formula data
Library/Homebrew/utils/repology.rb
@@ -21,16 +21,19 @@ def query_api(last_package_in_response = "") end def single_package_query(name) - url = "https://repology.org/api/v1/project/#{name}" - - output, _errors, _status = curl_output(url.to_s) - data = JSON.parse(output) - - homebrew = data.select do |repo| - repo["repo"] == "homebrew" + url = %W[ + https://repology.org/tools/project-by?repo=homebrew& + name_type=srcname&target_page=api_v1_project&name=#{name} + ].join + + output, _errors, _status = curl_output("--location", url.to_s) + + begin + data = JSON.parse(output) + { name => data } + rescue + nil end - - homebrew.empty? ? nil : { name => data } end def parse_api_response(limit = nil) @@ -59,7 +62,8 @@ def parse_api_response(limit = nil) end def latest_version(repositories) - # TODO: explain unique + # The status is "unique" when the package is present only in Homebrew, so Repology + # has no way of knowing if the package is up-to-date. is_unique = repositories.find do |repo| repo["status"] == "unique" end.present? @@ -70,7 +74,7 @@ def latest_version(repositories) repo["status"] == "newest" end - # TODO: explain when latest can be blank + # Repology cannot identify "newest" versions for packages without a version scheme return "no latest version" if latest_version.blank? latest_version["version"]
true
Other
Homebrew
brew
61ff1d7e74243b9cb72057a951e22f2428e9f2d3.json
dev-cmd/bump: fix skip message handling
Library/Homebrew/dev-cmd/bump.rb
@@ -82,9 +82,9 @@ def bump end def livecheck_result(formula) - skip_result = Livecheck.skip_conditions(formula, json: true, full_name: false, quiet: false) - if skip_result != false - return "skipped#{" - #{skip_result[:messages].join(", ")}" if skip_result[:messages].present?}" + skip_result = Livecheck.skip_conditions(formula, json: true, full_name: false, quiet: false).presence + if skip_result + return "#{skip_result[:status]}#{" - #{skip_result[:messages].join(", ")}" if skip_result[:messages].present?}" end version_info = Livecheck.latest_version(
false
Other
Homebrew
brew
180d8ca2b2aa860e84764469dabfef6c0109fd01.json
utils/curl: use specs when checking http content problems
Library/Homebrew/resource_auditor.rb
@@ -105,7 +105,7 @@ def audit_urls # pull request. next if url.match?(%r{^https://dl.bintray.com/homebrew/mirror/}) - if http_content_problem = curl_check_http_content(url) + if http_content_problem = curl_check_http_content(url, specs: specs) problem http_content_problem end elsif strategy <= GitDownloadStrategy
true
Other
Homebrew
brew
180d8ca2b2aa860e84764469dabfef6c0109fd01.json
utils/curl: use specs when checking http content problems
Library/Homebrew/utils/curl.rb
@@ -151,7 +151,7 @@ def url_protected_by_incapsula?(details) details[:headers].match?(/^Set-Cookie: incap_ses_/i) end - def curl_check_http_content(url, user_agents: [:default], check_content: false, strict: false) + def curl_check_http_content(url, specs: {}, user_agents: [:default], check_content: false, strict: false) return unless url.start_with? "http" secure_url = url.sub(/\Ahttp:/, "https:") @@ -160,7 +160,8 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false, if url != secure_url user_agents.each do |user_agent| secure_details = - curl_http_content_headers_and_checksum(secure_url, hash_needed: true, user_agent: user_agent) + curl_http_content_headers_and_checksum(secure_url, specs: specs, hash_needed: true, + user_agent: user_agent) next unless http_status_ok?(secure_details[:status]) @@ -172,7 +173,8 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false, details = nil user_agents.each do |user_agent| - details = curl_http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: user_agent) + details = + curl_http_content_headers_and_checksum(url, specs: specs, hash_needed: hash_needed, user_agent: user_agent) break if http_status_ok?(details[:status]) end @@ -237,12 +239,13 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false, "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end - def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) + def curl_http_content_headers_and_checksum(url, specs: {}, hash_needed: false, user_agent: :default) file = Tempfile.new.tap(&:close) + specs = specs.flat_map { |option, argument| ["--#{option.to_s.tr("_", "-")}", argument] } max_time = hash_needed ? "600" : "25" output, _, status = curl_output( - "--dump-header", "-", "--output", file.path, "--location", + *specs, "--dump-header", "-", "--output", file.path, "--location", "--connect-timeout", "15", "--max-time", max_time, "--retry-max-time", max_time, url, user_agent: user_agent )
true
Other
Homebrew
brew
b7b624c9bfb5c6a28776ffed8f1811fd82e5b022.json
parser: clarify errors for invalid number of args
Library/Homebrew/cli/parser.rb
@@ -599,21 +599,16 @@ def check_constraint_violations end def check_named_args(args) + types = Array(@named_args_type).map do |type| + next type if type.is_a? Symbol + + :subcommand + end.compact.uniq + exception = if @min_named_args && args.size < @min_named_args - if @named_args_type.present? - types = Array(@named_args_type) - if types.any? { |arg| arg.is_a? String } - MinNamedArgumentsError.new(@min_named_args) - else - list = types.map { |type| type.to_s.tr("_", " ") } - list = list.to_sentence two_words_connector: " or ", last_word_connector: " or " - UsageError.new("this command requires a #{list} argument") - end - else - MinNamedArgumentsError.new(@min_named_args) - end + MinNamedArgumentsError.new(@min_named_args, types: types, exact: @min_named_args == @max_named_args) elsif @max_named_args && args.size > @max_named_args - MaxNamedArgumentsError.new(@max_named_args) + MaxNamedArgumentsError.new(@max_named_args, types: types) end raise exception if exception @@ -688,23 +683,33 @@ def initialize(arg1, arg2) class MaxNamedArgumentsError < UsageError extend T::Sig - sig { params(maximum: Integer).void } - def initialize(maximum) + sig { params(maximum: Integer, types: T::Array[Symbol]).void } + def initialize(maximum, types: []) super case maximum when 0 "This command does not take named arguments." else - "This command does not take more than #{maximum} named #{"argument".pluralize(maximum)}" + types << :named if types.empty? + arg_types = types.map { |type| type.to_s.tr("_", " ") } + .to_sentence two_words_connector: " or ", last_word_connector: " or " + + "This command does not take more than #{maximum} #{arg_types} #{"argument".pluralize(maximum)}." end end end class MinNamedArgumentsError < UsageError extend T::Sig - sig { params(minimum: Integer).void } - def initialize(minimum) - super "This command requires at least #{minimum} named #{"argument".pluralize(minimum)}." + sig { params(minimum: Integer, types: T::Array[Symbol], exact: T::Boolean).void } + def initialize(minimum, types: [], exact: false) + number_phrase = exact ? "exactly" : "at least" + + types << :named if types.empty? + arg_types = types.map { |type| type.to_s.tr("_", " ") } + .to_sentence two_words_connector: " or ", last_word_connector: " or " + + super "This command requires #{number_phrase} #{minimum} #{arg_types} #{"argument".pluralize(minimum)}." end end end
true
Other
Homebrew
brew
b7b624c9bfb5c6a28776ffed8f1811fd82e5b022.json
parser: clarify errors for invalid number of args
Library/Homebrew/test/cli/parser_spec.rb
@@ -475,18 +475,58 @@ expect { parser_none.parse([]) }.not_to raise_error end + it "displays the correct error message with no arg types and min" do + parser = described_class.new do + named_args min: 2 + end + expect { parser.parse([]) }.to raise_error( + Homebrew::CLI::MinNamedArgumentsError, /This command requires at least 2 named arguments/ + ) + end + + it "displays the correct error message with no arg types and number" do + parser = described_class.new do + named_args number: 2 + end + expect { parser.parse([]) }.to raise_error( + Homebrew::CLI::MinNamedArgumentsError, /This command requires exactly 2 named arguments/ + ) + end + + it "displays the correct error message with no arg types and max" do + parser = described_class.new do + named_args max: 1 + end + expect { parser.parse(%w[foo bar]) }.to raise_error( + Homebrew::CLI::MaxNamedArgumentsError, /This command does not take more than 1 named argument/ + ) + end + it "displays the correct error message with an array of strings" do parser = described_class.new do - named_args %w[on off], min: 1 + named_args %w[on off], number: 1 end - expect { parser.parse([]) }.to raise_error(Homebrew::CLI::MinNamedArgumentsError) + expect { parser.parse([]) }.to raise_error( + Homebrew::CLI::MinNamedArgumentsError, /This command requires exactly 1 subcommand/ + ) end it "displays the correct error message with an array of symbols" do parser = described_class.new do named_args [:formula, :cask], min: 1 end - expect { parser.parse([]) }.to raise_error(UsageError, /this command requires a formula or cask argument/) + expect { parser.parse([]) }.to raise_error( + Homebrew::CLI::MinNamedArgumentsError, /This command requires at least 1 formula or cask argument/ + ) + end + + it "displays the correct error message with an array of symbols and max" do + parser = described_class.new do + named_args [:formula, :cask], max: 1 + end + expect { parser.parse(%w[foo bar]) }.to raise_error( + Homebrew::CLI::MaxNamedArgumentsError, /This command does not take more than 1 formula or cask argument/ + ) end end @@ -509,7 +549,9 @@ formula_parser = described_class.new do named :formula end - expect { formula_parser.parse([]) }.to raise_error(UsageError, /this command requires a formula argument/) + expect { formula_parser.parse([]) }.to raise_error( + Homebrew::CLI::MinNamedArgumentsError, /This command requires exactly 1 formula argument/ + ) end it "doesn't allow more than the specified number of arguments" do
true
Other
Homebrew
brew
49b9b6cf3fa5d01db46b0645696aca072dfa8665.json
dev-cmd/extract: Improve the usage instructions - A friend got an error message when trying to use `brew extract` and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code for `extract_args`. Before: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [--version=] [--force] formula ... [...] Error: Invalid usage: this command requires a formula argument ``` After: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [options] formula tap [...] Error: Invalid usage: This command requires at least 2 named arguments. ``` - I don't like the "at least 2" phrasing here but that's a dive into the arg parsing code that I don't have time for right now. An alternative was `named_args [:formula, :destination_tap]`, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also tried `min: 2, max: 2` and that was the same "at least 2" message.
Library/Homebrew/dev-cmd/extract.rb
@@ -83,6 +83,7 @@ module Homebrew sig { returns(CLI::Parser) } def extract_args Homebrew::CLI::Parser.new do + usage_banner "`extract` [<--version>`=`] [<--force>] <formula> <tap>" description <<~EOS Look through repository history to find the most recent version of <formula> and create a copy in <tap>`/Formula/`<formula>`@`<version>`.rb`. If the tap is not @@ -95,7 +96,7 @@ def extract_args switch "-f", "--force", description: "Overwrite the destination formula if it already exists." - named_args :formula, number: 2 + named_args number: 2 end end
true
Other
Homebrew
brew
49b9b6cf3fa5d01db46b0645696aca072dfa8665.json
dev-cmd/extract: Improve the usage instructions - A friend got an error message when trying to use `brew extract` and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code for `extract_args`. Before: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [--version=] [--force] formula ... [...] Error: Invalid usage: this command requires a formula argument ``` After: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [options] formula tap [...] Error: Invalid usage: This command requires at least 2 named arguments. ``` - I don't like the "at least 2" phrasing here but that's a dive into the arg parsing code that I don't have time for right now. An alternative was `named_args [:formula, :destination_tap]`, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also tried `min: 2, max: 2` and that was the same "at least 2" message.
completions/bash/brew
@@ -898,7 +898,6 @@ _brew_extract() { return ;; esac - __brew_complete_formulae } _brew_fetch() {
true
Other
Homebrew
brew
49b9b6cf3fa5d01db46b0645696aca072dfa8665.json
dev-cmd/extract: Improve the usage instructions - A friend got an error message when trying to use `brew extract` and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code for `extract_args`. Before: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [--version=] [--force] formula ... [...] Error: Invalid usage: this command requires a formula argument ``` After: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [options] formula tap [...] Error: Invalid usage: This command requires at least 2 named arguments. ``` - I don't like the "at least 2" phrasing here but that's a dive into the arg parsing code that I don't have time for right now. An alternative was `named_args [:formula, :destination_tap]`, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also tried `min: 2, max: 2` and that was the same "at least 2" message.
docs/Manpage.md
@@ -1019,7 +1019,7 @@ or open the Homebrew repository for editing if no formula is provided. * `--cask`: Treat all named arguments as casks. -### `extract` [*`--version`*`=`] [*`--force`*] *`formula`* ... +### `extract` [*`--version`*`=`] [*`--force`*] *`formula`* *`tap`* Look through repository history to find the most recent version of *`formula`* and create a copy in *`tap`*`/Formula/`*`formula`*`@`*`version`*`.rb`. If the tap is not
true
Other
Homebrew
brew
49b9b6cf3fa5d01db46b0645696aca072dfa8665.json
dev-cmd/extract: Improve the usage instructions - A friend got an error message when trying to use `brew extract` and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code for `extract_args`. Before: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [--version=] [--force] formula ... [...] Error: Invalid usage: this command requires a formula argument ``` After: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [options] formula tap [...] Error: Invalid usage: This command requires at least 2 named arguments. ``` - I don't like the "at least 2" phrasing here but that's a dive into the arg parsing code that I don't have time for right now. An alternative was `named_args [:formula, :destination_tap]`, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also tried `min: 2, max: 2` and that was the same "at least 2" message.
manpages/brew.1
@@ -1417,7 +1417,7 @@ Treat all named arguments as formulae\. \fB\-\-cask\fR Treat all named arguments as casks\. . -.SS "\fBextract\fR [\fI\-\-version\fR\fB=\fR] [\fI\-\-force\fR] \fIformula\fR \.\.\." +.SS "\fBextract\fR [\fI\-\-version\fR\fB=\fR] [\fI\-\-force\fR] \fIformula\fR \fItap\fR" Look through repository history to find the most recent version of \fIformula\fR and create a copy in \fItap\fR\fB/Formula/\fR\fIformula\fR\fB@\fR\fIversion\fR\fB\.rb\fR\. If the tap is not installed yet, attempt to install/clone the tap before continuing\. To extract a formula from a tap that is not \fBhomebrew/core\fR use its fully\-qualified form of \fIuser\fR\fB/\fR\fIrepo\fR\fB/\fR\fIformula\fR\. . .TP
true
Other
Homebrew
brew
e13dc902df8fdabfde7f50c1a2a3d772e77d6c5e.json
Add tests and fix type signature
Library/Homebrew/dev-cmd/release-notes.rb
@@ -32,6 +32,9 @@ def release_notes_args def release_notes args = release_notes_args.parse + # TODO: (2.8) Deprecate this command now that the `brew release` command exists. + # odeprecated "`brew release-notes`" + previous_tag = args.named.first if previous_tag.present? @@ -56,7 +59,7 @@ def release_notes odie "Ref #{ref} does not exist!" end - release_notes = ReleaseNotes.generate_release_notes previous_tag, end_ref, markdown: T.must(args.markdown?) + release_notes = ReleaseNotes.generate_release_notes previous_tag, end_ref, markdown: args.markdown? $stderr.puts "Release notes between #{previous_tag} and #{end_ref}:" puts release_notes
true
Other
Homebrew
brew
e13dc902df8fdabfde7f50c1a2a3d772e77d6c5e.json
Add tests and fix type signature
Library/Homebrew/release_notes.rb
@@ -10,7 +10,7 @@ module ReleaseNotes module_function sig { - params(start_ref: T.any(String, Version), end_ref: T.any(String, Version), markdown: T::Boolean) + params(start_ref: T.any(String, Version), end_ref: T.any(String, Version), markdown: T.nilable(T::Boolean)) .returns(String) } def generate_release_notes(start_ref, end_ref, markdown: false)
true
Other
Homebrew
brew
e13dc902df8fdabfde7f50c1a2a3d772e77d6c5e.json
Add tests and fix type signature
Library/Homebrew/test/dev-cmd/release_spec.rb
@@ -0,0 +1,8 @@ +# typed: false +# frozen_string_literal: true + +require "cmd/shared_examples/args_parse" + +describe "Homebrew.release_args" do + it_behaves_like "parseable arguments" +end
true
Other
Homebrew
brew
e13dc902df8fdabfde7f50c1a2a3d772e77d6c5e.json
Add tests and fix type signature
Library/Homebrew/test/release_notes_spec.rb
@@ -0,0 +1,33 @@ +# typed: false +# frozen_string_literal: true + +require "release_notes" + +describe ReleaseNotes do + before do + HOMEBREW_REPOSITORY.cd do + system "git", "init" + system "git", "commit", "--allow-empty", "-m", "Initial commit" + system "git", "tag", "release-notes-testing" + system "git", "commit", "--allow-empty", "-m", "Merge pull request #1 from Homebrew/fix", "-m", "Do something" + system "git", "commit", "--allow-empty", "-m", "make a change" + system "git", "commit", "--allow-empty", "-m", "Merge pull request #2 from User/fix", "-m", "Do something else" + end + end + + describe ".generate_release_notes" do + it "generates release notes" do + expect(described_class.generate_release_notes("release-notes-testing", "HEAD")).to eq <<~NOTES + https://github.com/Homebrew/brew/pull/2 (@User) - Do something else + https://github.com/Homebrew/brew/pull/1 (@Homebrew) - Do something + NOTES + end + + it "generates markdown release notes" do + expect(described_class.generate_release_notes("release-notes-testing", "HEAD", markdown: true)).to eq <<~NOTES + - [Do something else](https://github.com/Homebrew/brew/pull/2) (@User) + - [Do something](https://github.com/Homebrew/brew/pull/1) (@Homebrew) + NOTES + end + end +end
true
Other
Homebrew
brew
a06bd4e45df2a98a05e6752d7a662807176b3a77.json
version/parser: add unit tests
Library/Homebrew/test/version/parser_spec.rb
@@ -0,0 +1,81 @@ +# typed: false +# frozen_string_literal: true + +require "version/parser" + +describe Version::Parser do + specify "::new" do + expect { described_class.new } + .to raise_error("Version::Parser is declared as abstract; it cannot be instantiated") + end + + describe Version::RegexParser do + specify "::new" do + # TODO: see https://github.com/sorbet/sorbet/issues/2374 + # expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) } + # .to raise_error("Version::RegexParser is declared as abstract; it cannot be instantiated") + expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) }.not_to raise_error + end + + specify "::process_spec" do + expect { described_class.process_spec(Pathname(TEST_TMPDIR)) } + .to raise_error("The method `process_spec` on #<Class:Version::RegexParser> is declared as `abstract`. " \ + "It does not have an implementation.") + end + end + + describe Version::UrlParser do + specify "::new" do + expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) }.not_to raise_error + end + + specify "::process_spec" do + expect(described_class.process_spec(Pathname("#{TEST_TMPDIR}/testdir-0.1.test"))) + .to eq("#{TEST_TMPDIR}/testdir-0.1.test") + + expect(described_class.process_spec(Pathname("https://sourceforge.net/foo_bar-1.21.tar.gz/download"))) + .to eq("https://sourceforge.net/foo_bar-1.21.tar.gz/download") + + expect(described_class.process_spec(Pathname("https://sf.net/foo_bar-1.21.tar.gz/download"))) + .to eq("https://sf.net/foo_bar-1.21.tar.gz/download") + + expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1"))) + .to eq("https://brew.sh/testball-0.1") + + expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1.tgz"))) + .to eq("https://brew.sh/testball-0.1.tgz") + end + end + + describe Version::StemParser do + before { Pathname("#{TEST_TMPDIR}/testdir-0.1.test").mkpath } + + after { Pathname("#{TEST_TMPDIR}/testdir-0.1.test").unlink } + + specify "::new" do + expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) }.not_to raise_error + end + + describe "::process_spec" do + it "works with directories" do + expect(described_class.process_spec(Pathname("#{TEST_TMPDIR}/testdir-0.1.test"))).to eq("testdir-0.1.test") + end + + it "works with SourceForge URLs with /download suffix" do + expect(described_class.process_spec(Pathname("https://sourceforge.net/foo_bar-1.21.tar.gz/download"))) + .to eq("foo_bar-1.21") + + expect(described_class.process_spec(Pathname("https://sf.net/foo_bar-1.21.tar.gz/download"))) + .to eq("foo_bar-1.21") + end + + it "works with URLs without file extension" do + expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1"))).to eq("testball-0.1") + end + + it "works with URLs with file extension" do + expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1.tgz"))).to eq("testball-0.1") + end + end + end +end
true
Other
Homebrew
brew
a06bd4e45df2a98a05e6752d7a662807176b3a77.json
version/parser: add unit tests
Library/Homebrew/version/parser.rb
@@ -27,7 +27,7 @@ def initialize(regex, &block) sig { override.params(spec: Pathname).returns(T.nilable(String)) } def parse(spec) - match = @regex.match(process_spec(spec)) + match = @regex.match(self.class.process_spec(spec)) return if match.blank? version = match.captures.first @@ -38,15 +38,15 @@ def parse(spec) end sig { abstract.params(spec: Pathname).returns(String) } - def process_spec(spec); end + def self.process_spec(spec); end end # @api private class UrlParser < RegexParser extend T::Sig sig { override.params(spec: Pathname).returns(String) } - def process_spec(spec) + def self.process_spec(spec) spec.to_s end end @@ -55,11 +55,11 @@ def process_spec(spec) class StemParser < RegexParser extend T::Sig - SOURCEFORGE_DOWNLOAD_REGEX = %r{((?:sourceforge\.net|sf\.net)/.*)/download$}.freeze + SOURCEFORGE_DOWNLOAD_REGEX = %r{(?:sourceforge\.net|sf\.net)/.*/download$}.freeze NO_FILE_EXTENSION_REGEX = /\.[^a-zA-Z]+$/.freeze sig { override.params(spec: Pathname).returns(String) } - def process_spec(spec) + def self.process_spec(spec) return spec.basename.to_s if spec.directory? spec_s = spec.to_s
true
Other
Homebrew
brew
b4df0d5c10a2b3ca984ff054d5b2fdd95f182515.json
cmd/cleanup: add desc about all to --prune
Library/Homebrew/cmd/cleanup.rb
@@ -22,7 +22,8 @@ def cleanup_args #{days} days old. This can be adjusted with `HOMEBREW_CLEANUP_MAX_AGE_DAYS`. EOS flag "--prune=", - description: "Remove all cache files older than specified <days>." + description: "Remove all cache files older than specified <days>. "\ + "If you want to remove everything, use `--prune=all`." switch "-n", "--dry-run", description: "Show what would be removed, but do not actually remove anything." switch "-s",
true
Other
Homebrew
brew
b4df0d5c10a2b3ca984ff054d5b2fdd95f182515.json
cmd/cleanup: add desc about all to --prune
docs/Manpage.md
@@ -77,7 +77,7 @@ only do this for the given formulae and casks. Removes all downloads more than 120 days old. This can be adjusted with `HOMEBREW_CLEANUP_MAX_AGE_DAYS`. * `--prune`: - Remove all cache files older than specified *`days`*. + Remove all cache files older than specified *`days`*. If you want to remove everything, use `--prune=all`. * `-n`, `--dry-run`: Show what would be removed, but do not actually remove anything. * `-s`:
true
Other
Homebrew
brew
b4df0d5c10a2b3ca984ff054d5b2fdd95f182515.json
cmd/cleanup: add desc about all to --prune
manpages/brew.1
@@ -68,7 +68,7 @@ Remove stale lock files and outdated downloads for all formulae and casks, and r . .TP \fB\-\-prune\fR -Remove all cache files older than specified \fIdays\fR\. +Remove all cache files older than specified \fIdays\fR\. If you want to remove everything, use \fB\-\-prune=all\fR\. . .TP \fB\-n\fR, \fB\-\-dry\-run\fR
true
Other
Homebrew
brew
e1f73e407ad5e5ac4dcb602625d930235ed49a53.json
Add ReleaseNotes module
Library/Homebrew/dev-cmd/release-notes.rb
@@ -2,6 +2,7 @@ # frozen_string_literal: true require "cli/parser" +require "release_notes" module Homebrew extend T::Sig @@ -55,25 +56,9 @@ def release_notes odie "Ref #{ref} does not exist!" end - output = Utils.popen_read( - "git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{previous_tag}..#{end_ref}" - ).lines.grep(/Merge pull request/) - - output.map! do |s| - s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*}, - "https://github.com/Homebrew/brew/pull/\\1 (@\\2)") - end - if args.markdown? - output.map! do |s| - /(.*\d)+ \(@(.+)\) - (.*)/ =~ s - "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})" - end - end + release_notes = ReleaseNotes.generate_release_notes previous_tag, end_ref, markdown: T.must(args.markdown?) $stderr.puts "Release notes between #{previous_tag} and #{end_ref}:" - if args.markdown? && args.named.first - puts "Release notes for major and minor releases can be found in the [Homebrew blog](https://brew.sh/blog/)." - end - puts output + puts release_notes end end
true
Other
Homebrew
brew
e1f73e407ad5e5ac4dcb602625d930235ed49a53.json
Add ReleaseNotes module
Library/Homebrew/dev-cmd/release.rb
@@ -2,6 +2,7 @@ # frozen_string_literal: true require "cli/parser" +require "release_notes" module Homebrew extend T::Sig @@ -59,31 +60,24 @@ def release end new_version = if args.major? - Version.new [latest_version.major.to_i + 1, 0, 0].join(".") + Version.new "#{latest_version.major.to_i + 1}.0.0" elsif args.minor? - Version.new [latest_version.major, latest_version.minor.to_i + 1, 0].join(".") + Version.new "#{latest_version.major}.#{latest_version.minor.to_i + 1}.0" else - Version.new [latest_version.major, latest_version.minor, latest_version.patch.to_i + 1].join(".") + Version.new "#{latest_version.major}.#{latest_version.minor}.#{latest_version.patch.to_i + 1}" end.to_s ohai "Creating draft release for version #{new_version}" + release_notes = if args.major? || args.minor? - ["Release notes for this release can be found on the [Homebrew blog](https://brew.sh/blog/#{new_version})."] + "Release notes for this release can be found on the [Homebrew blog](https://brew.sh/blog/#{new_version}).\n" else - [] - end - release_notes += Utils.popen_read( - "git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{latest_version}..origin/HEAD" - ).lines.grep(/Merge pull request/).map! do |s| - pr = s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*}, - "https://github.com/Homebrew/brew/pull/\\1 (@\\2)") - /(.*\d)+ \(@(.+)\) - (.*)/ =~ pr - "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})" + "" end + release_notes += ReleaseNotes.generate_release_notes latest_version, "origin/HEAD", markdown: true begin - release = GitHub.create_or_update_release "Homebrew", "brew", new_version, - body: release_notes.join("\n"), draft: true + release = GitHub.create_or_update_release "Homebrew", "brew", new_version, body: release_notes, draft: true rescue *GitHub::API_ERRORS => e odie "Unable to create release: #{e.message}!" end
true
Other
Homebrew
brew
e1f73e407ad5e5ac4dcb602625d930235ed49a53.json
Add ReleaseNotes module
Library/Homebrew/release_notes.rb
@@ -0,0 +1,35 @@ +# typed: true +# frozen_string_literal: true + +# Helper functions for generating release notes. +# +# @api private +module ReleaseNotes + extend T::Sig + + module_function + + sig { + params(start_ref: T.any(String, Version), end_ref: T.any(String, Version), markdown: T::Boolean) + .returns(String) + } + def generate_release_notes(start_ref, end_ref, markdown: false) + log_output = Utils.popen_read( + "git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{start_ref}..#{end_ref}" + ).lines.grep(/Merge pull request/) + + log_output.map! do |s| + s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*}, + "https://github.com/Homebrew/brew/pull/\\1 (@\\2)") + end + + if markdown + log_output.map! do |s| + /(.*\d)+ \(@(.+)\) - (.*)/ =~ s + "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})\n" + end + end + + log_output.join + end +end
true
Other
Homebrew
brew
dad19391421041680c7d19cedf3569a734335a64.json
Fix HOMEBREW_BOOTSNAP setup - rename to `homebrew_bootsnap.rb` to avoid conflicting with the `bootsnap.rb` we need to `require` - if the `require` fails: run bundler (until we vendor this gem)
Library/.rubocop.yml
@@ -370,7 +370,7 @@ Sorbet/FalseSigil: - "/**/{Formula,Casks}/*.rb" - "**/{Formula,Casks}/*.rb" - "Homebrew/test/**/Casks/**/*.rb" - - "Homebrew/bootsnap.rb" + - "Homebrew/homebrew_bootsnap.rb" Sorbet/StrictSigil: Enabled: true
true
Other
Homebrew
brew
dad19391421041680c7d19cedf3569a734335a64.json
Fix HOMEBREW_BOOTSNAP setup - rename to `homebrew_bootsnap.rb` to avoid conflicting with the `bootsnap.rb` we need to `require` - if the `require` fails: run bundler (until we vendor this gem)
Library/Homebrew/homebrew_bootsnap.rb
@@ -7,7 +7,21 @@ raise "Needs HOMEBREW_BOOTSNAP!" unless ENV["HOMEBREW_BOOTSNAP"] require "rubygems" -require "bootsnap" + +begin + require "bootsnap" +rescue LoadError + raise if ENV["HOMEBREW_BOOTSNAP_RETRY"] + + Dir.chdir(HOMEBREW_LIBRARY_PATH) do + system "bundle", "install", "--standalone" + end + + ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1" + exec ENV["HOMEBREW_BREW_FILE"], *ARGV +end + +ENV.delete("HOMEBREW_BOOTSNAP_RETRY") Bootsnap.setup( cache_dir: "#{ENV["HOMEBREW_TEMP"]}/homebrew-bootsnap",
true
Other
Homebrew
brew
dad19391421041680c7d19cedf3569a734335a64.json
Fix HOMEBREW_BOOTSNAP setup - rename to `homebrew_bootsnap.rb` to avoid conflicting with the `bootsnap.rb` we need to `require` - if the `require` fails: run bundler (until we vendor this gem)
Library/Homebrew/load_path.rb
@@ -10,7 +10,7 @@ require "vendor/bundle/bundler/setup" if ENV["HOMEBREW_BOOTSNAP"] - require "bootsnap" + require "homebrew_bootsnap" else $LOAD_PATH.select! { |d| Pathname(d).directory? } $LOAD_PATH.uniq!
true
Other
Homebrew
brew
ecfad29347d9e58b9499144cab0a539d9e863ce9.json
tap: write untapped setting only on manual untap
Library/Homebrew/cmd/untap.rb
@@ -43,7 +43,7 @@ def untap end end - tap.uninstall + tap.uninstall manual: true end end end
true
Other
Homebrew
brew
ecfad29347d9e58b9499144cab0a539d9e863ce9.json
tap: write untapped setting only on manual untap
Library/Homebrew/tap.rb
@@ -363,7 +363,7 @@ def link_completions_and_manpages end # Uninstall this {Tap}. - def uninstall + def uninstall(manual: false) require "descriptions" raise TapUnavailableError, name unless installed? @@ -386,7 +386,7 @@ def uninstall Commands.rebuild_commands_completion_list clear_cache - return unless official? + return if !manual || !official? untapped = self.class.untapped_official_taps return if untapped.include? name
true
Other
Homebrew
brew
15761a283d4dca679f28ea1141f3da7a0b3247ef.json
cleanup: raise failures and handle later. These are already handled and outputted as a group in `cmd/cleanup.rb`. Fixes https://github.com/Homebrew/brew/issues/10379
Library/Homebrew/cleanup.rb
@@ -249,7 +249,7 @@ def cleanup_cask(cask, ds_store: true) end def cleanup_keg(keg) - cleanup_path(keg) { keg.uninstall } + cleanup_path(keg) { keg.uninstall(raise_failures: true) } rescue Errno::EACCES => e opoo e.message unremovable_kegs << keg
true
Other
Homebrew
brew
15761a283d4dca679f28ea1141f3da7a0b3247ef.json
cleanup: raise failures and handle later. These are already handled and outputted as a group in `cmd/cleanup.rb`. Fixes https://github.com/Homebrew/brew/issues/10379
Library/Homebrew/keg.rb
@@ -319,7 +319,7 @@ def remove_opt_record opt_record.parent.rmdir_if_possible end - def uninstall + def uninstall(raise_failures: false) CacheStoreDatabase.use(:linkage) do |db| break unless db.created? @@ -333,6 +333,8 @@ def uninstall remove_old_aliases remove_oldname_opt_record rescue Errno::EACCES, Errno::ENOTEMPTY + raise if raise_failures + odie <<~EOS Could not remove #{name} keg! Do so manually: sudo rm -rf #{path}
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
.gitignore
@@ -85,6 +85,7 @@ # Ignore dependencies we don't wish to vendor **/vendor/bundle/ruby/*/gems/ast-*/ +**/vendor/bundle/ruby/*/gems/bootsnap-*/ **/vendor/bundle/ruby/*/gems/bundler-*/ **/vendor/bundle/ruby/*/gems/byebug-*/ **/vendor/bundle/ruby/*/gems/coderay-*/ @@ -105,6 +106,7 @@ **/vendor/bundle/ruby/*/gems/mime-types-*/ **/vendor/bundle/ruby/*/gems/mini_portile2-*/ **/vendor/bundle/ruby/*/gems/minitest-*/ +**/vendor/bundle/ruby/*/gems/msgpack-*/ **/vendor/bundle/ruby/*/gems/mustache-*/ **/vendor/bundle/ruby/*/gems/net-http-digest_auth-*/ **/vendor/bundle/ruby/*/gems/net-http-persistent-*/
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
Library/.rubocop.yml
@@ -370,6 +370,7 @@ Sorbet/FalseSigil: - "/**/{Formula,Casks}/*.rb" - "**/{Formula,Casks}/*.rb" - "Homebrew/test/**/Casks/**/*.rb" + - "Homebrew/bootsnap.rb" Sorbet/StrictSigil: Enabled: true
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
Library/Homebrew/Gemfile
@@ -3,6 +3,7 @@ source "https://rubygems.org" # installed gems (should all be require: false) +gem "bootsnap", require: false if ENV["HOMEBREW_BOOTSNAP"] gem "byebug", require: false gem "codecov", require: false gem "nokogiri", require: false
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
Library/Homebrew/bootsnap.rb
@@ -0,0 +1,20 @@ +# typed: ignore +# frozen_string_literal: true + +# TODO: make this `typed: true` when HOMEBREW_BOOTSNAP is enabled by +# default and/or we vendor bootsnap and the RBI file. + +raise "Needs HOMEBREW_BOOTSNAP!" unless ENV["HOMEBREW_BOOTSNAP"] + +require "rubygems" +require "bootsnap" + +Bootsnap.setup( + cache_dir: "#{ENV["HOMEBREW_TEMP"]}/homebrew-bootsnap", + development_mode: false, # TODO: use ENV["HOMEBREW_DEVELOPER"]?, + load_path_cache: true, + autoload_paths_cache: true, + disable_trace: true, + compile_cache_iseq: true, + compile_cache_yaml: true, +)
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
Library/Homebrew/global.rb
@@ -1,6 +1,8 @@ # typed: false # frozen_string_literal: true +require_relative "load_path" + require "English" require "json" require "json/add/exception" @@ -14,8 +16,6 @@ RUBY_PATH = Pathname.new(RbConfig.ruby).freeze RUBY_BIN = RUBY_PATH.dirname.freeze -require_relative "load_path" - require "rubygems" # Only require "core_ext" here to ensure we're only requiring the minimum of # what we need.
true
Other
Homebrew
brew
683ae7ff53052d365dcbe4aba8d4d5bb7b6026b5.json
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap > Bootsnap is a library that plugs into Ruby, with optional support > for ActiveSupport and YAML, to optimize and cache expensive > computations. https://github.com/Shopify/bootsnap For our case that translates to "repeated calls to `brew` have reductions in the time spend `require`ing speeding up the process boot time". For example: ``` $ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget" Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget Time (mean ± σ): 2.417 s ± 0.032 s [User: 659.0 ms, System: 855.5 ms] Range (min … max): 2.382 s … 2.464 s 10 runs Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget Time (mean ± σ): 1.862 s ± 0.064 s [User: 425.3 ms, System: 566.8 ms] Range (min … max): 1.736 s … 1.952 s 10 runs Summary 'export HOMEBREW_BOOTSNAP=1; brew info wget' ran 1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget' ```
Library/Homebrew/load_path.rb
@@ -9,5 +9,9 @@ require "vendor/bundle/bundler/setup" -$LOAD_PATH.select! { |d| Pathname(d).directory? } -$LOAD_PATH.uniq! +if ENV["HOMEBREW_BOOTSNAP"] + require "bootsnap" +else + $LOAD_PATH.select! { |d| Pathname(d).directory? } + $LOAD_PATH.uniq! +end
true
Other
Homebrew
brew
7ba88097223a819292f1d5b7e0fcf16f6ad57a21.json
Update RBI files for sorbet.
Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
@@ -7673,11 +7673,6 @@ class Hash def self.try_convert(_); end end -class HeadVersion - extend ::T::Private::Methods::MethodHooks - extend ::T::Private::Methods::SingletonMethodHooks -end - module Homebrew MAX_PORT = ::T.let(nil, ::T.untyped) MIN_PORT = ::T.let(nil, ::T.untyped) @@ -29737,6 +29732,13 @@ module Utils end class Version::Token + extend ::T::Private::Abstract::Hooks + extend ::T::InterfaceWrapper::Helpers + extend ::T::Private::Methods::MethodHooks + extend ::T::Private::Methods::SingletonMethodHooks +end + +class Version extend ::T::Private::Methods::MethodHooks extend ::T::Private::Methods::SingletonMethodHooks end
false
Other
Homebrew
brew
47db90603fb1f926e574f9d07c492a5956abdee0.json
Update RBI files for concurrent-ruby.
Library/Homebrew/sorbet/rbi/gems/concurrent-ruby@1.1.8.rbi
@@ -1,6 +1,6 @@ # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `concurrent-ruby` gem. -# Please instead update this file by running `tapioca sync --exclude json`. +# Please instead update this file by running `tapioca sync`. # typed: true @@ -477,7 +477,7 @@ module Concurrent::Concern::Observable protected def observers; end - def observers=(_); end + def observers=(_arg0); end end class Concurrent::ConcurrentUpdateError < ::ThreadError @@ -714,10 +714,10 @@ class Concurrent::LockFreeStack::Node def next_node; end def value; end - def value=(_); end + def value=(_arg0); end class << self - def [](*_); end + def [](*_arg0); end end end @@ -1465,10 +1465,10 @@ class Concurrent::SerializedExecution::Job < ::Struct def executor=(_); end class << self - def [](*_); end + def [](*_arg0); end def inspect; end def members; end - def new(*_); end + def new(*_arg0); end end end @@ -1881,10 +1881,10 @@ class Concurrent::Transaction::ReadLogEntry < ::Struct def version=(_); end class << self - def [](*_); end + def [](*_arg0); end def inspect; end def members; end - def new(*_); end + def new(*_arg0); end end end
true
Other
Homebrew
brew
47db90603fb1f926e574f9d07c492a5956abdee0.json
Update RBI files for concurrent-ruby.
Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
@@ -7673,11 +7673,6 @@ class Hash def self.try_convert(_); end end -class HeadVersion - extend ::T::Private::Methods::MethodHooks - extend ::T::Private::Methods::SingletonMethodHooks -end - module Homebrew MAX_PORT = ::T.let(nil, ::T.untyped) MIN_PORT = ::T.let(nil, ::T.untyped) @@ -29737,6 +29732,13 @@ module Utils end class Version::Token + extend ::T::Private::Abstract::Hooks + extend ::T::InterfaceWrapper::Helpers + extend ::T::Private::Methods::MethodHooks + extend ::T::Private::Methods::SingletonMethodHooks +end + +class Version extend ::T::Private::Methods::MethodHooks extend ::T::Private::Methods::SingletonMethodHooks end
true
Other
Homebrew
brew
a04b4890a9185088af9d1664ba044d91e05697c7.json
Remove unneeded `export` Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
docs/Shell-Completion.md
@@ -47,7 +47,7 @@ This must be done before `compinit` is called. Note that if you are using Oh My ```diff eval $(/opt/homebrew/bin/brew shellenv) -+ export FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH ++ FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH ``` You may also need to forcibly rebuild `zcompdump`:
false
Other
Homebrew
brew
1e4fef812347453c27e38955cb1d9c6da90c58b4.json
usage string generator: fix handling of dashed-commands
Library/Homebrew/cli/parser.rb
@@ -122,7 +122,7 @@ def initialize(&block) @args = Homebrew::CLI::Args.new - @command_name = caller_locations(2, 1).first.label.chomp("_args") + @command_name = caller_locations(2, 1).first.label.chomp("_args").tr("_", "-") @constraints = [] @conflicts = [] @@ -449,12 +449,12 @@ def hide_from_man_page! }.freeze def generate_usage_banner - command_names = ["`#{@command_name.tr("_", "-")}`"] + command_names = ["`#{@command_name}`"] aliases_to_skip = %w[instal uninstal] command_names += Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |command_alias, command| next if aliases_to_skip.include? command_alias - "`#{command_alias.tr("_", "-")}`" if command == @command_name + "`#{command_alias}`" if command == @command_name end.compact.sort options = if @non_global_processed_options.empty?
true
Other
Homebrew
brew
1e4fef812347453c27e38955cb1d9c6da90c58b4.json
usage string generator: fix handling of dashed-commands
docs/Manpage.md
@@ -711,7 +711,7 @@ that directory doesn't exist, `$(brew --repository)/Cellar`. If *`formula`* is provided, display the location in the Cellar where *`formula`* would be installed, without any sort of versioned directory as the last path. -### `--env` [*`--shell`*`=`] [*`--plain`*] [*`formula`* ...] +### `--env`, `environment` [*`--shell`*`=`] [*`--plain`*] [*`formula`* ...] Summarise Homebrew's build environment as a plain list. @@ -737,13 +737,13 @@ is or would be installed. * `--unbrewed`: List files in Homebrew's prefix not installed by Homebrew. -### `--repository` [*`tap`* ...] +### `--repository`, `--repo` [*`tap`* ...] Display where Homebrew's `.git` directory is located. If *`user`*`/`*`repo`* are provided, display where tap *`user`*`/`*`repo`*'s directory is located. -### `--version` +### `--version`, `-v` Print the version numbers of Homebrew, Homebrew/homebrew-core and Homebrew/homebrew-cask (if tapped) to standard output.
true
Other
Homebrew
brew
1e4fef812347453c27e38955cb1d9c6da90c58b4.json
usage string generator: fix handling of dashed-commands
manpages/brew.1
@@ -964,7 +964,7 @@ Display Homebrew\'s Cellar path\. \fIDefault:\fR \fB$(brew \-\-prefix)/Cellar\fR .P If \fIformula\fR is provided, display the location in the Cellar where \fIformula\fR would be installed, without any sort of versioned directory as the last path\. . -.SS "\fB\-\-env\fR [\fI\-\-shell\fR\fB=\fR] [\fI\-\-plain\fR] [\fIformula\fR \.\.\.]" +.SS "\fB\-\-env\fR, \fBenvironment\fR [\fI\-\-shell\fR\fB=\fR] [\fI\-\-plain\fR] [\fIformula\fR \.\.\.]" Summarise Homebrew\'s build environment as a plain list\. . .P @@ -999,13 +999,13 @@ If \fIformula\fR is provided, display the location in the Cellar where \fIformul \fB\-\-unbrewed\fR List files in Homebrew\'s prefix not installed by Homebrew\. . -.SS "\fB\-\-repository\fR [\fItap\fR \.\.\.]" +.SS "\fB\-\-repository\fR, \fB\-\-repo\fR [\fItap\fR \.\.\.]" Display where Homebrew\'s \fB\.git\fR directory is located\. . .P If \fIuser\fR\fB/\fR\fIrepo\fR are provided, display where tap \fIuser\fR\fB/\fR\fIrepo\fR\'s directory is located\. . -.SS "\fB\-\-version\fR" +.SS "\fB\-\-version\fR, \fB\-v\fR" Print the version numbers of Homebrew, Homebrew/homebrew\-core and Homebrew/homebrew\-cask (if tapped) to standard output\. . .SH "DEVELOPER COMMANDS"
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/.rubocop.yml
@@ -51,3 +51,7 @@ Naming/PredicateName: Style/HashAsLastArrayItem: Exclude: - 'test/utils/spdx_spec.rb' + +Style/BlockDelimiters: + BracesRequiredMethods: + - 'sig'
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/bintray.rb
@@ -43,15 +43,15 @@ def open_api(url, *args, auth: true) curl(*args, url, print_stdout: false, secrets: key) end - sig do + sig { params(local_file: String, repo: String, package: String, version: String, remote_file: String, sha256: T.nilable(String), warn_on_error: T.nilable(T::Boolean)).void - end + } def upload(local_file, repo:, package:, version:, remote_file:, sha256: nil, warn_on_error: false) unless File.exist? local_file msg = "#{local_file} for upload doesn't exist!" @@ -78,13 +78,13 @@ def upload(local_file, repo:, package:, version:, remote_file:, sha256: nil, war opoo msg end - sig do + sig { params(repo: String, package: String, version: String, file_count: T.nilable(Integer), warn_on_error: T.nilable(T::Boolean)).void - end + } def publish(repo:, package:, version:, file_count:, warn_on_error: false) url = "#{API_URL}/content/#{@bintray_org}/#{repo}/#{package}/#{version}/publish" upload_args = %w[--request POST] @@ -113,12 +113,12 @@ def stable_mirrored?(url) status_code.start_with?("2") end - sig do + sig { params(formula: Formula, repo: String, publish_package: T::Boolean, warn_on_error: T::Boolean).returns(String) - end + } def mirror_formula(formula, repo: "mirror", publish_package: false, warn_on_error: false) package = Utils::Bottles::Bintray.package formula.name @@ -202,11 +202,11 @@ def file_delete_instructions(bintray_repo, bintray_package, filename) EOS end - sig do + sig { params(bottles_hash: T::Hash[String, T.untyped], publish_package: T::Boolean, warn_on_error: T.nilable(T::Boolean)).void - end + } def upload_bottles(bottles_hash, publish_package: false, warn_on_error: false) formula_packaged = {}
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cask/artifact/relocated.rb
@@ -41,10 +41,10 @@ def resolve_target(target, base_dir: config.public_send(self.class.dirmethod)) attr_reader :source, :target - sig do + sig { params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target: T.nilable(T.any(String, Pathname))) .void - end + } def initialize(cask, source, target: nil) super(cask)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cask/cmd/upgrade.rb
@@ -57,7 +57,7 @@ def run ) end - sig do + sig { params( casks: Cask, args: Homebrew::CLI::Args, @@ -70,7 +70,7 @@ def run quarantine: T.nilable(T::Boolean), require_sha: T.nilable(T::Boolean), ).returns(T::Boolean) - end + } def self.upgrade_casks( *casks, args:,
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cask/config.rb
@@ -72,10 +72,10 @@ def self.from_json(json, ignore_invalid_keys: false) ) end - sig do + sig { params(config: T::Enumerable[[T.any(String, Symbol), T.any(String, Pathname, T::Array[String])]]) .returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) - end + } def self.canonicalize(config) config.map do |k, v| key = k.to_sym @@ -91,14 +91,14 @@ def self.canonicalize(config) sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) } attr_accessor :explicit - sig do + sig { params( default: T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]), env: T.nilable(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]), explicit: T::Hash[Symbol, T.any(String, Pathname, T::Array[String])], ignore_invalid_keys: T::Boolean, ).void - end + } def initialize(default: nil, env: nil, explicit: {}, ignore_invalid_keys: false) @default = self.class.canonicalize(self.class.defaults.merge(default)) if default @env = self.class.canonicalize(env) if env
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cask/url.rb
@@ -16,7 +16,7 @@ class URL extend Forwardable def_delegators :uri, :path, :scheme, :to_s - sig do + sig { params( uri: T.any(URI::Generic, String), verified: T.nilable(String), @@ -34,7 +34,7 @@ class URL from_block: T::Boolean, caller_location: Thread::Backtrace::Location, ).returns(T.untyped) - end + } def initialize( uri, verified: nil,
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cli/named_args.rb
@@ -42,10 +42,10 @@ def to_formulae # Convert named arguments to {Formula} or {Cask} objects. # If both a formula and cask with the same name exist, returns # the formula and prints a warning unless `only` is specified. - sig do + sig { params(only: T.nilable(Symbol), ignore_unavailable: T.nilable(T::Boolean), method: T.nilable(Symbol)) .returns(T::Array[T.any(Formula, Keg, Cask::Cask)]) - end + } def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil) @to_formulae_and_casks ||= {} @to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name| @@ -175,10 +175,10 @@ def to_kegs end end - sig do + sig { params(only: T.nilable(Symbol), ignore_unavailable: T.nilable(T::Boolean), all_kegs: T.nilable(T::Boolean)) .returns([T::Array[Keg], T::Array[Cask::Cask]]) - end + } def to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil) method = all_kegs ? :kegs : :keg @to_kegs_to_casks ||= {}
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/cli/parser.rb
@@ -355,14 +355,14 @@ def formula_options @formula_options = true end - sig do + sig { params( type: T.any(Symbol, T::Array[String], T::Array[Symbol]), number: T.nilable(Integer), min: T.nilable(Integer), max: T.nilable(Integer), ).void - end + } def named_args(type = nil, number: nil, min: nil, max: nil) if number.present? && (min.present? || max.present?) raise ArgumentError, "Do not specify both `number` and `min` or `max`"
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/dev-cmd/bump-unversioned-casks.rb
@@ -84,10 +84,10 @@ def self.bump_unversioned_casks end end - sig do + sig { params(cask: Cask::Cask, state: T::Hash[String, T.untyped], dry_run: T.nilable(T::Boolean)) .returns(T.nilable(T::Hash[String, T.untyped])) - end + } def self.bump_unversioned_cask(cask, state:, dry_run:) ohai "Checking #{cask.full_name}"
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/ENV.rb
@@ -31,15 +31,15 @@ def activate_extensions!(env: nil) end end - sig do + sig { params( env: T.nilable(String), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(String), _block: T.proc.returns(T.untyped), ).returns(T.untyped) - end + } def with_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil, &_block) old_env = to_hash.dup tmp_env = to_hash.dup.extend(EnvActivation)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/ENV.rbi
@@ -24,10 +24,10 @@ module EnvMethods sig { params(key: String).returns(T.nilable(String)) } def delete(key); end - sig do + sig { params(other: T.any(T::Hash[String, String], Sorbet::Private::Static::ENVClass)) .returns(Sorbet::Private::Static::ENVClass) - end + } def replace(other); end sig { returns(T::Hash[String, String]) }
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/ENV/shared.rb
@@ -33,14 +33,14 @@ module SharedEnvExtension ].freeze private_constant :SANITIZED_VARS - sig do + sig { params( formula: T.nilable(Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(T::Boolean), ).void - end + } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil) @formula = formula @cc = cc
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/ENV/std.rb
@@ -14,14 +14,14 @@ module Stdenv SAFE_CFLAGS_FLAGS = "-w -pipe" # @private - sig do + sig { params( formula: T.nilable(Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(T::Boolean), ).void - end + } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil) super
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/ENV/super.rb
@@ -42,14 +42,14 @@ def reset end # @private - sig do + sig { params( formula: T.nilable(Formula), cc: T.nilable(String), build_bottle: T.nilable(T::Boolean), bottle_arch: T.nilable(T::Boolean), ).void - end + } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil) super send(compiler)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/extend/pathname.rb
@@ -85,12 +85,12 @@ class Pathname BOTTLE_EXTNAME_RX = /(\.[a-z0-9_]+\.bottle\.(\d+\.)?tar\.gz)$/.freeze # Moves a file from the original location to the {Pathname}'s. - sig do + sig { params(sources: T.any( Resource, Resource::Partial, String, Pathname, T::Array[T.any(String, Pathname)], T::Hash[T.any(String, Pathname), String] )).void - end + } def install(*sources) sources.each do |src| case src @@ -140,11 +140,11 @@ def install_p(src, new_basename) private :install_p # Creates symlinks to sources in this folder. - sig do + sig { params( sources: T.any(String, Pathname, T::Array[T.any(String, Pathname)], T::Hash[T.any(String, Pathname), String]), ).void - end + } def install_symlink(*sources) sources.each do |src| case src @@ -309,11 +309,11 @@ def verify_checksum(expected) alias to_str to_s - sig do + sig { type_parameters(:U).params( _block: T.proc.params(path: Pathname).returns(T.type_parameter(:U)), ).returns(T.type_parameter(:U)) - end + } def cd(&_block) Dir.chdir(self) { yield self } end @@ -413,14 +413,14 @@ def env_script_all_files(dst, env) end # Writes an exec script that invokes a Java jar. - sig do + sig { params( target_jar: T.any(String, Pathname), script_name: T.any(String, Pathname), java_opts: String, java_version: T.nilable(String), ).returns(Integer) - end + } def write_jar_script(target_jar, script_name, java_opts = "", java_version: nil) (self/script_name).write <<~EOS #!/bin/bash
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/livecheck/livecheck.rb
@@ -62,7 +62,7 @@ def livecheck_strategy_names # Executes the livecheck logic for each formula/cask in the # `formulae_and_casks_to_check` array and prints the results. - sig do + sig { params( formulae_and_casks_to_check: T::Enumerable[T.any(Formula, Cask::Cask)], full_name: T::Boolean, @@ -72,7 +72,7 @@ def livecheck_strategy_names quiet: T::Boolean, verbose: T::Boolean, ).void - end + } def run_checks( formulae_and_casks_to_check, full_name: false, json: false, newer_only: false, debug: false, quiet: false, verbose: false @@ -260,15 +260,15 @@ def formula_name(formula, full_name: false) full_name ? formula.full_name : formula.name end - sig do + sig { params( formula_or_cask: T.any(Formula, Cask::Cask), status_str: String, messages: T.nilable(T::Array[String]), full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def status_hash(formula_or_cask, status_str, messages = nil, full_name: false, verbose: false) formula = formula_or_cask if formula_or_cask.is_a?(Formula) cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask) @@ -311,12 +311,12 @@ def print_latest_version(info, verbose:) puts "#{formula_or_cask_s} : #{current_s} ==> #{latest_s}" end - sig do + sig { params( livecheck_url: T.any(String, Symbol), formula_or_cask: T.any(Formula, Cask::Cask), ).returns(T.nilable(String)) - end + } def livecheck_url_to_string(livecheck_url, formula_or_cask) case livecheck_url when String @@ -396,15 +396,15 @@ def preprocess_url(url) # Identifies the latest version of the formula and returns a Hash containing # the version information. Returns nil if a latest version couldn't be found. - sig do + sig { params( formula_or_cask: T.any(Formula, Cask::Cask), json: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, debug: T::Boolean, ).returns(T.nilable(Hash)) - end + } def latest_version(formula_or_cask, json: false, full_name: false, verbose: false, debug: false) formula = formula_or_cask if formula_or_cask.is_a?(Formula) cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/livecheck/skip_conditions.rb
@@ -14,14 +14,14 @@ module SkipConditions module_function - sig do + sig { params( formula_or_cask: T.any(Formula, Cask::Cask), livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def formula_or_cask_skip(formula_or_cask, livecheckable, full_name: false, verbose: false) formula = formula_or_cask if formula_or_cask.is_a?(Formula) @@ -51,14 +51,14 @@ def formula_or_cask_skip(formula_or_cask, livecheckable, full_name: false, verbo Livecheck.status_hash(formula_or_cask, "skipped", skip_messages, full_name: full_name, verbose: verbose) end - sig do + sig { params( formula: Formula, _livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def formula_head_only(formula, _livecheckable, full_name: false, verbose: false) return {} if !formula.head_only? || formula.any_version_installed? @@ -71,84 +71,84 @@ def formula_head_only(formula, _livecheckable, full_name: false, verbose: false) ) end - sig do + sig { params( formula: Formula, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def formula_deprecated(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.deprecated? || livecheckable Livecheck.status_hash(formula, "deprecated", full_name: full_name, verbose: verbose) end - sig do + sig { params( formula: Formula, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def formula_disabled(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.disabled? || livecheckable Livecheck.status_hash(formula, "disabled", full_name: full_name, verbose: verbose) end - sig do + sig { params( formula: Formula, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def formula_versioned(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.versioned_formula? || livecheckable Livecheck.status_hash(formula, "versioned", full_name: full_name, verbose: verbose) end - sig do + sig { params( cask: Cask::Cask, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def cask_discontinued(cask, livecheckable, full_name: false, verbose: false) return {} if !cask.discontinued? || livecheckable Livecheck.status_hash(cask, "discontinued", full_name: full_name, verbose: verbose) end - sig do + sig { params( cask: Cask::Cask, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def cask_version_latest(cask, livecheckable, full_name: false, verbose: false) return {} if !(cask.present? && cask.version&.latest?) || livecheckable Livecheck.status_hash(cask, "latest", full_name: full_name, verbose: verbose) end - sig do + sig { params( cask: Cask::Cask, livecheckable: T::Boolean, full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false) return {} if !(cask.present? && cask.url&.unversioned?) || livecheckable @@ -175,13 +175,13 @@ def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false) # If a formula/cask should be skipped, we return a hash from # `Livecheck#status_hash`, which contains a `status` type and sometimes # error `messages`. - sig do + sig { params( formula_or_cask: T.any(Formula, Cask::Cask), full_name: T::Boolean, verbose: T::Boolean, ).returns(Hash) - end + } def skip_information(formula_or_cask, full_name: false, verbose: false) livecheckable = formula_or_cask.livecheckable?
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/livecheck/strategy/page_match.rb
@@ -77,14 +77,14 @@ def self.page_matches(content, regex, &block) # @param provided_content [String] page content to use in place of # fetching via Strategy#page_content # @return [Hash] - sig do + sig { params( url: String, regex: T.nilable(Regexp), provided_content: T.nilable(String), block: T.nilable(T.proc.params(arg0: String).returns(T.any(T::Array[String], String))), ).returns(T::Hash[Symbol, T.untyped]) - end + } def self.find_versions(url, regex, provided_content = nil, &block) match_data = { matches: {}, regex: regex, url: url }
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/system_command.rb
@@ -64,7 +64,7 @@ def run! result end - sig do + sig { params( executable: T.any(String, Pathname), args: T::Array[T.any(String, Integer, Float, URI::Generic)], @@ -79,7 +79,7 @@ def run! secrets: T.any(String, T::Array[String]), chdir: T.any(String, Pathname), ).void - end + } def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false, print_stdout: false, print_stderr: true, debug: nil, verbose: nil, secrets: [], chdir: T.unsafe(nil)) require "extend/ENV" @@ -224,14 +224,14 @@ class Result attr_accessor :command, :status, :exit_status - sig do + sig { params( command: T::Array[String], output: T::Array[[Symbol, String]], status: Process::Status, secrets: T::Array[String], ).void - end + } def initialize(command, output, status, secrets:) @command = command @output = output
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/unpack_strategy/zip.rb
@@ -22,10 +22,10 @@ def self.can_extract?(path) private - sig do + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean) .returns(SystemCommand::Result) - end + } def extract_to_dir(unpack_dir, basename:, verbose:) quiet_flags = verbose ? [] : ["-qq"] result = system_command! "unzip",
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/ast.rb
@@ -49,14 +49,14 @@ def process_source(source) [processed_source, root_node] end - sig do + sig { params( component_name: Symbol, component_type: Symbol, target_name: Symbol, target_type: T.nilable(Symbol), ).returns(T::Boolean) - end + } def component_match?(component_name:, component_type:, target_name:, target_type: nil) component_name == target_name && (target_type.nil? || component_type == target_type) end
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/git_repository.rb
@@ -4,27 +4,27 @@ module Utils extend T::Sig - sig do + sig { params( repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean, ).returns(T.nilable(String)) - end + } def self.git_head(repo = Pathname.pwd, length: nil, safe: true) return git_short_head(repo, length: length) if length.present? repo = Pathname(repo).extend(GitRepositoryExtension) repo.git_head(safe: safe) end - sig do + sig { params( repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean, ).returns(T.nilable(String)) - end + } def self.git_short_head(repo = Pathname.pwd, length: nil, safe: true) repo = Pathname(repo).extend(GitRepositoryExtension) repo.git_short_head(length: length, safe: safe)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/github/actions.rb
@@ -31,12 +31,12 @@ def self.path_relative_to_workspace(path) path.realpath.relative_path_from(workspace) end - sig do + sig { params( type: Symbol, message: String, file: T.nilable(T.any(String, Pathname)), line: T.nilable(Integer), column: T.nilable(Integer) ).void - end + } def initialize(type, message, file: nil, line: nil, column: nil) raise ArgumentError, "Unsupported type: #{type.inspect}" unless [:warning, :error].include?(type)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/inreplace.rb
@@ -40,14 +40,14 @@ def initialize(errors) # # @see StringInreplaceExtension # @api public - sig do + sig { params( paths: T.any(T::Array[T.untyped], String, Pathname), before: T.nilable(T.any(Regexp, String)), after: T.nilable(T.any(String, Symbol)), audit_result: T::Boolean, ).void - end + } def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter after = after.to_s if after.is_a? Symbol
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/pypi.rb
@@ -119,7 +119,7 @@ def update_pypi_url(url, version) end # Return true if resources were checked (even if no change). - sig do + sig { params( formula: Formula, version: T.nilable(String), @@ -130,7 +130,7 @@ def update_pypi_url(url, version) silent: T.nilable(T::Boolean), ignore_non_pypi_packages: T.nilable(T::Boolean), ).returns(T.nilable(T::Boolean)) - end + } def update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil, exclude_packages: nil, print_only: false, silent: false, ignore_non_pypi_packages: false)
true
Other
Homebrew
brew
fbafaff4fe46dd58bb2225331df512f79b857b2a.json
rubocop: require braces for Sorbet `sig`
Library/Homebrew/utils/string_inreplace_extension.rb
@@ -28,10 +28,10 @@ def sub!(before, after) # Same as `String#gsub!`, but warns if nothing was replaced. # # @api public - sig do + sig { params(before: T.any(Regexp, String), after: T.nilable(String), audit_result: T::Boolean) .returns(T.nilable(String)) - end + } def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter result = inreplace_string.gsub!(before, after) errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
true
Other
Homebrew
brew
a257d046efbedc2fe79a637106406671898ed87d.json
remove spurious call to $fish_pid
Library/Homebrew/cmd/shellenv.sh
@@ -6,7 +6,7 @@ #: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)` homebrew-shellenv() { - case "$(/bin/ps -p ${PPID:-$fish_pid} -c -o comm=)" in + case "$(/bin/ps -p $PPID -c -o comm=)" in fish|-fish) echo "set -gx HOMEBREW_PREFIX \"$HOMEBREW_PREFIX\";" echo "set -gx HOMEBREW_CELLAR \"$HOMEBREW_CELLAR\";"
false
Other
Homebrew
brew
5a9795016df3653a6f2eccbfb762cc8d17386cbd.json
completions: add tests for new methods
Library/Homebrew/completions.rb
@@ -97,7 +97,7 @@ def update_shell_completions! sig { params(command: String).returns(T::Boolean) } def command_gets_completions?(command) - return false if command.start_with? "cask " # TODO: remove when `brew cask` commands are removed + return false if command.start_with? "cask " # TODO: (2.8) remove when `brew cask` commands are removed command_options(command).any? end
true
Other
Homebrew
brew
5a9795016df3653a6f2eccbfb762cc8d17386cbd.json
completions: add tests for new methods
Library/Homebrew/test/completions_spec.rb
@@ -4,137 +4,241 @@ require "completions" describe Homebrew::Completions do + let(:completions_dir) { HOMEBREW_REPOSITORY/"completions" } let(:internal_path) { HOMEBREW_REPOSITORY/"Library/Taps/homebrew/homebrew-bar" } let(:external_path) { HOMEBREW_REPOSITORY/"Library/Taps/foo/homebrew-bar" } before do HOMEBREW_REPOSITORY.cd do system "git", "init" end + described_class::SHELLS.each do |shell| + (completions_dir/shell).mkpath + end internal_path.mkpath external_path.mkpath end - def setup_completions(external:) - (internal_path/"completions/bash/foo_internal").write "#foo completions" - if external - (external_path/"completions/bash/foo_external").write "#foo completions" - elsif (external_path/"completions/bash/foo_external").exist? - (external_path/"completions/bash/foo_external").delete - end - end - - def setup_completions_setting(state, setting: "linkcompletions") - HOMEBREW_REPOSITORY.cd do - system "git", "config", "--replace-all", "homebrew.#{setting}", state.to_s - end - end - - def read_completions_setting(setting: "linkcompletions") - HOMEBREW_REPOSITORY.cd do - Utils.popen_read("git", "config", "--get", "homebrew.#{setting}").chomp.presence - end - end - - def delete_completions_setting(setting: "linkcompletions") - HOMEBREW_REPOSITORY.cd do - system "git", "config", "--unset-all", "homebrew.#{setting}" - end - end - after do + FileUtils.rm_rf completions_dir FileUtils.rm_rf internal_path FileUtils.rm_rf external_path.dirname end - describe ".link!" do - it "sets homebrew.linkcompletions to true" do - setup_completions_setting false - expect { described_class.link! }.not_to raise_error - expect(read_completions_setting).to eq "true" - end + context "when linking or unlinking completions" do + def setup_completions(external:) + (internal_path/"completions/bash/foo_internal").write "#foo completions" + if external + (external_path/"completions/bash/foo_external").write "#foo completions" + elsif (external_path/"completions/bash/foo_external").exist? + (external_path/"completions/bash/foo_external").delete + end + end + + def setup_completions_setting(state, setting: "linkcompletions") + HOMEBREW_REPOSITORY.cd do + system "git", "config", "--replace-all", "homebrew.#{setting}", state.to_s + end + end + + def read_completions_setting(setting: "linkcompletions") + HOMEBREW_REPOSITORY.cd do + Utils.popen_read("git", "config", "--get", "homebrew.#{setting}").chomp.presence + end + end + + def delete_completions_setting(setting: "linkcompletions") + HOMEBREW_REPOSITORY.cd do + system "git", "config", "--unset-all", "homebrew.#{setting}" + end + end + + describe ".link!" do + it "sets homebrew.linkcompletions to true" do + setup_completions_setting false + expect { described_class.link! }.not_to raise_error + expect(read_completions_setting).to eq "true" + end + + it "sets homebrew.linkcompletions to true if unset" do + delete_completions_setting + expect { described_class.link! }.not_to raise_error + expect(read_completions_setting).to eq "true" + end + + it "keeps homebrew.linkcompletions set to true" do + setup_completions_setting true + expect { described_class.link! }.not_to raise_error + expect(read_completions_setting).to eq "true" + end + end + + describe ".unlink!" do + it "sets homebrew.linkcompletions to false" do + setup_completions_setting true + expect { described_class.unlink! }.not_to raise_error + expect(read_completions_setting).to eq "false" + end + + it "sets homebrew.linkcompletions to false if unset" do + delete_completions_setting + expect { described_class.unlink! }.not_to raise_error + expect(read_completions_setting).to eq "false" + end + + it "keeps homebrew.linkcompletions set to false" do + setup_completions_setting false + expect { described_class.unlink! }.not_to raise_error + expect(read_completions_setting).to eq "false" + end + end + + describe ".link_completions?" do + it "returns true if homebrew.linkcompletions is true" do + setup_completions_setting true + expect(described_class.link_completions?).to be true + end + + it "returns false if homebrew.linkcompletions is false" do + setup_completions_setting false + expect(described_class.link_completions?).to be false + end + + it "returns false if homebrew.linkcompletions is not set" do + expect(described_class.link_completions?).to be false + end + end + + describe ".completions_to_link?" do + it "returns false if only internal taps have completions" do + setup_completions external: false + expect(described_class.completions_to_link?).to be false + end + + it "returns true if external taps have completions" do + setup_completions external: true + expect(described_class.completions_to_link?).to be true + end + end + + describe ".show_completions_message_if_needed" do + it "doesn't show the message if there are no completions to link" do + setup_completions external: false + delete_completions_setting setting: :completionsmessageshown + expect { described_class.show_completions_message_if_needed }.not_to output.to_stdout + end + + it "doesn't show the message if there are completions to link but the message has already been shown" do + setup_completions external: true + setup_completions_setting true, setting: :completionsmessageshown + expect { described_class.show_completions_message_if_needed }.not_to output.to_stdout + end - it "sets homebrew.linkcompletions to true if unset" do - delete_completions_setting - expect { described_class.link! }.not_to raise_error - expect(read_completions_setting).to eq "true" - end - - it "keeps homebrew.linkcompletions set to true" do - setup_completions_setting true - expect { described_class.link! }.not_to raise_error - expect(read_completions_setting).to eq "true" + it "shows the message if there are completions to link and the message hasn't already been shown" do + setup_completions external: true + delete_completions_setting setting: :completionsmessageshown + + message = /Homebrew completions for external commands are unlinked by default!/ + expect { described_class.show_completions_message_if_needed } + .to output(message).to_stdout + end end end - describe ".unlink!" do - it "sets homebrew.linkcompletions to false" do - setup_completions_setting true - expect { described_class.unlink! }.not_to raise_error - expect(read_completions_setting).to eq "false" - end - - it "sets homebrew.linkcompletions to false if unset" do - delete_completions_setting - expect { described_class.unlink! }.not_to raise_error - expect(read_completions_setting).to eq "false" - end - - it "keeps homebrew.linkcompletions set to false" do - setup_completions_setting false - expect { described_class.unlink! }.not_to raise_error - expect(read_completions_setting).to eq "false" - end - end - - describe ".link_completions?" do - it "returns true if homebrew.linkcompletions is true" do - setup_completions_setting true - expect(described_class.link_completions?).to be true - end - - it "returns false if homebrew.linkcompletions is false" do - setup_completions_setting false - expect(described_class.link_completions?).to be false - end - - it "returns false if homebrew.linkcompletions is not set" do - expect(described_class.link_completions?).to be false - end - end - - describe ".completions_to_link?" do - it "returns false if only internal taps have completions" do - setup_completions external: false - expect(described_class.completions_to_link?).to be false - end - - it "returns true if external taps have completions" do - setup_completions external: true - expect(described_class.completions_to_link?).to be true - end - end - - describe ".show_completions_message_if_needed" do - it "doesn't show the message if there are no completions to link" do - setup_completions external: false - delete_completions_setting setting: :completionsmessageshown - expect { described_class.show_completions_message_if_needed }.not_to output.to_stdout - end - - it "doesn't show the message if there are completions to link but the message has already been shown" do - setup_completions external: true - setup_completions_setting true, setting: :completionsmessageshown - expect { described_class.show_completions_message_if_needed }.not_to output.to_stdout - end - - it "shows the message if there are completions to link and the message hasn't already been shown" do - setup_completions external: true - delete_completions_setting setting: :completionsmessageshown - - message = /Homebrew completions for external commands are unlinked by default!/ - expect { described_class.show_completions_message_if_needed } - .to output(message).to_stdout + context "when generating completions" do + describe ".update_shell_completions!" do + it "generates shell completions" do + described_class.update_shell_completions! + expect(completions_dir/"bash/brew").to be_a_file + end + end + + describe ".command_options" do + it "returns an array of options for a ruby command" do + expected_options = %w[--debug --help --hide --quiet --verbose] + expect(described_class.command_options("missing")).to eq expected_options + end + + it "returns an array of options for a shell command" do + expected_options = %w[--debug --force --help --merge --preinstall --verbose] + expect(described_class.command_options("update")).to eq expected_options + end + + it "handles --[no]- options correctly" do + options = described_class.command_options("audit") + expect(options.include?("--appcast")).to eq true + expect(options.include?("--no-appcast")).to eq true + end + + it "return an empty array if command is not found" do + expect(described_class.command_options("foobar")).to eq [] + end + + it "return an empty array for a command with no options" do + expect(described_class.command_options("help")).to eq [] + end + + it "will list global options only once if overriden" do + count = 0 + described_class.command_options("upgrade").each do |opt| + count += 1 if opt == "--verbose" + end + expect(count).to eq 1 + end + end + + describe ".command_gets_completions?" do + it "returns true for a non-cask command with options" do + expect(described_class.command_gets_completions?("install")).to eq true + end + + it "returns false for a non-cask command with no options" do + expect(described_class.command_gets_completions?("help")).to eq false + end + + it "returns false for a cask command" do + expect(described_class.command_gets_completions?("cask install")).to eq false + end + end + + describe ".generate_bash_subcommand_completion" do + it "returns nil if completions aren't needed" do + expect(described_class.generate_bash_subcommand_completion("help")).to be_nil + end + + it "returns appropriate completion for a ruby command" do + completion = described_class.generate_bash_subcommand_completion("missing") + expect(completion).to match(/^_brew_missing\(\) {/) + expect(completion).to match(/__brewcomp "\n +--debug\n +--help\n +--hide\n +--quiet\n +--verbose/s) + expect(completion).to match(/__brew_complete_formulae\n}$/) + end + + it "returns appropriate completion for a shell command" do + completion = described_class.generate_bash_subcommand_completion("update") + options_regex = /__brewcomp "\n +--debug\n +--force\n +--help\n +--merge\n +--preinstall\n +--verbose/ + expect(completion).to match(/^_brew_update\(\) {/) + expect(completion).to match(options_regex) + end + + it "returns appropriate completion for a command with multiple named arg types" do + completion = described_class.generate_bash_subcommand_completion("upgrade") + expect(completion).to match(/__brew_complete_outdated_formulae\n __brew_complete_outdated_casks\n}$/) + end + end + + describe ".generate_bash_completion_file" do + it "returns the correct completion file" do + file = described_class.generate_bash_completion_file(%w[install missing update]) + expect(file).to match(/^__brewcomp\(\) {$/) + expect(file).to match(/^_brew_install\(\) {$/) + expect(file).to match(/^_brew_missing\(\) {$/) + expect(file).to match(/^_brew_update\(\) {$/) + expect(file).to match(/^_brew\(\) {$/) + expect(file).to match(/^ {4}install\) _brew_install ;;/) + expect(file).to match(/^ {4}missing\) _brew_missing ;;/) + expect(file).to match(/^ {4}update\) _brew_update ;;/) + expect(file).to match(/^complete -o bashdefault -o default -F _brew brew$/) + end end end end
true
Other
Homebrew
brew
94a33b1d2ed98335e7e8ff4182f1c5f1b0821e6e.json
livecheck: compare actual version for casks
Library/Homebrew/livecheck/livecheck.rb
@@ -149,6 +149,9 @@ def run_checks( Version.new(formula_or_cask.version) end + current_str = current.to_s + current = actual_version(formula_or_cask, current) + latest = if formula&.head_only? formula.head.downloader.fetch_last_commit else @@ -172,6 +175,9 @@ def run_checks( latest = Version.new(m[1]) end + latest_str = latest.to_s + latest = actual_version(formula_or_cask, latest) + is_outdated = if formula&.head_only? # A HEAD-only formula is considered outdated if the latest upstream # commit hash is different than the installed version's commit hash @@ -186,8 +192,8 @@ def run_checks( info[:formula] = name if formula info[:cask] = name if cask info[:version] = { - current: current.to_s, - latest: latest.to_s, + current: current_str, + latest: latest_str, outdated: is_outdated, newer_than_upstream: is_newer_than_upstream, } @@ -243,6 +249,8 @@ def formula_or_cask_name(formula_or_cask, full_name: false) formula_name(formula_or_cask, full_name: full_name) when Cask::Cask cask_name(formula_or_cask, full_name: full_name) + else + T.absurd(formula_or_cask) end end @@ -347,6 +355,8 @@ def checkable_urls(formula_or_cask) urls << formula_or_cask.appcast.to_s if formula_or_cask.appcast urls << formula_or_cask.url.to_s if formula_or_cask.url urls << formula_or_cask.homepage if formula_or_cask.homepage + else + T.absurd(formula_or_cask) end urls.compact @@ -536,7 +546,7 @@ def latest_version(formula_or_cask, json: false, full_name: false, verbose: fals next if match_version_map.blank? version_info = { - latest: Version.new(match_version_map.values.max), + latest: Version.new(match_version_map.values.max_by { |v| actual_version(formula_or_cask, v) }), } if json && verbose @@ -560,5 +570,17 @@ def latest_version(formula_or_cask, json: false, full_name: false, verbose: fals nil end + + sig { params(formula_or_cask: T.any(Formula, Cask::Cask), version: Version).returns(Version) } + def actual_version(formula_or_cask, version) + case formula_or_cask + when Formula + version + when Cask::Cask + Version.new(Cask::DSL::Version.new(version.to_s).before_comma) + else + T.absurd(formula_or_cask) + end + end end end
false
Other
Homebrew
brew
9bf409111c29af56667cd86a390f46e0b5561c7d.json
git_repository: raise error instead of returning nil if `safe`
Library/Homebrew/extend/git_repository.rb
@@ -34,20 +34,14 @@ def git_origin=(origin) # Gets the full commit hash of the HEAD commit. sig { params(safe: T::Boolean).returns(T.nilable(String)) } def git_head(safe: false) - return if !git? || !Utils::Git.available? - - Utils.popen_read(Utils::Git.git, "rev-parse", "--verify", "-q", "HEAD", safe: safe, chdir: self).chomp.presence + popen_git("rev-parse", "--verify", "-q", "HEAD", safe: safe) end # Gets a short commit hash of the HEAD commit. sig { params(length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String)) } def git_short_head(length: nil, safe: false) - return if !git? || !Utils::Git.available? - - git = Utils::Git.git - short_arg = length&.to_s&.prepend("=") - Utils.popen_read(git, "rev-parse", "--short#{short_arg}", "--verify", "-q", "HEAD", safe: safe, chdir: self) - .chomp.presence + short_arg = length.present? ? "--short=#{length}" : "--short" + popen_git("rev-parse", short_arg, "--verify", "-q", "HEAD", safe: safe) end # Gets the relative date of the last commit, e.g. "1 hour ago" @@ -96,4 +90,23 @@ def git_commit_message(commit = "HEAD") Utils.popen_read(Utils::Git.git, "log", "-1", "--pretty=%B", commit, "--", chdir: self, err: :out).strip.presence end + + private + + sig { params(args: T.untyped, safe: T::Boolean).returns(T.nilable(String)) } + def popen_git(*args, safe: false) + unless git? + return unless safe + + raise "Not a Git repository: #{self}" + end + + unless Utils::Git.available? + return unless safe + + raise "Git is unavailable" + end + + T.unsafe(Utils).popen_read(Utils::Git.git, *args, safe: safe, chdir: self).chomp.presence + end end
true
Other
Homebrew
brew
9bf409111c29af56667cd86a390f46e0b5561c7d.json
git_repository: raise error instead of returning nil if `safe`
Library/Homebrew/test/utils/git_repository_spec.rb
@@ -17,24 +17,82 @@ let(:short_head_revision) { HOMEBREW_CACHE.cd { `git rev-parse --short HEAD`.chomp } } describe ".git_head" do - it "returns the revision at HEAD" do + it "returns the revision at HEAD if repo parameter is specified" do expect(described_class.git_head(HOMEBREW_CACHE)).to eq(head_revision) expect(described_class.git_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5]) + end + + it "returns the revision at HEAD if repo parameter is omitted" do HOMEBREW_CACHE.cd do expect(described_class.git_head).to eq(head_revision) expect(described_class.git_head(length: 5)).to eq(head_revision[0...5]) end end + + context "when directory is not a Git repository" do + it "returns nil if `safe` parameter is `false`" do + expect(described_class.git_head(TEST_TMPDIR, safe: false)).to eq(nil) + end + + it "raises an error if `safe` parameter is `true`" do + expect { described_class.git_head(TEST_TMPDIR, safe: true) } + .to raise_error("Not a Git repository: #{TEST_TMPDIR}") + end + end + + context "when Git is unavailable" do + before do + allow(Utils::Git).to receive(:available?).and_return(false) + end + + it "returns nil if `safe` parameter is `false`" do + expect(described_class.git_head(HOMEBREW_CACHE, safe: false)).to eq(nil) + end + + it "raises an error if `safe` parameter is `true`" do + expect { described_class.git_head(HOMEBREW_CACHE, safe: true) } + .to raise_error("Git is unavailable") + end + end end describe ".git_short_head" do - it "returns the short revision at HEAD" do + it "returns the short revision at HEAD if repo parameter is specified" do expect(described_class.git_short_head(HOMEBREW_CACHE)).to eq(short_head_revision) expect(described_class.git_short_head(HOMEBREW_CACHE, length: 5)).to eq(head_revision[0...5]) + end + + it "returns the short revision at HEAD if repo parameter is omitted" do HOMEBREW_CACHE.cd do expect(described_class.git_short_head).to eq(short_head_revision) expect(described_class.git_short_head(length: 5)).to eq(head_revision[0...5]) end end + + context "when directory is not a Git repository" do + it "returns nil if `safe` parameter is `false`" do + expect(described_class.git_short_head(TEST_TMPDIR, safe: false)).to eq(nil) + end + + it "raises an error if `safe` parameter is `true`" do + expect { described_class.git_short_head(TEST_TMPDIR, safe: true) } + .to raise_error("Not a Git repository: #{TEST_TMPDIR}") + end + end + + context "when Git is unavailable" do + before do + allow(Utils::Git).to receive(:available?).and_return(false) + end + + it "returns nil if `safe` parameter is `false`" do + expect(described_class.git_short_head(HOMEBREW_CACHE, safe: false)).to eq(nil) + end + + it "raises an error if `safe` parameter is `true`" do + expect { described_class.git_short_head(HOMEBREW_CACHE, safe: true) } + .to raise_error("Git is unavailable") + end + end end end
true
Other
Homebrew
brew
9bf409111c29af56667cd86a390f46e0b5561c7d.json
git_repository: raise error instead of returning nil if `safe`
Library/Homebrew/utils/git_repository.rb
@@ -5,7 +5,11 @@ module Utils extend T::Sig sig do - params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String)) + params( + repo: T.any(String, Pathname), + length: T.nilable(Integer), + safe: T::Boolean, + ).returns(T.nilable(String)) end def self.git_head(repo = Pathname.pwd, length: nil, safe: true) return git_short_head(repo, length: length) if length.present? @@ -15,7 +19,11 @@ def self.git_head(repo = Pathname.pwd, length: nil, safe: true) end sig do - params(repo: T.any(String, Pathname), length: T.nilable(Integer), safe: T::Boolean).returns(T.nilable(String)) + params( + repo: T.any(String, Pathname), + length: T.nilable(Integer), + safe: T::Boolean, + ).returns(T.nilable(String)) end def self.git_short_head(repo = Pathname.pwd, length: nil, safe: true) repo = Pathname(repo).extend(GitRepositoryExtension)
true
Other
Homebrew
brew
6d3d88d33e4c0ee16b1e955f05adf889f221f8dc.json
Apply suggestions from code review Co-authored-by: Eric Knibbe <enk3@outlook.com>
docs/External-Commands.md
@@ -70,7 +70,7 @@ Install any `gem` package into a self-contained Homebrew Cellar location: <https Note this can also be installed with `brew install brew-gem`. ## External commands in taps -External commands can be hosted in a [tap](Taps.md) to allow users to easy install and use the command. See [How to Create and Maintain a Tap](How-to-Create-and-Maintain-a-Tap.md) for more details about creating and maintaining a tap. +External commands can be hosted in a [tap](Taps.md) to allow users to easily install and use them. See [How to Create and Maintain a Tap](How-to-Create-and-Maintain-a-Tap.md) for more details about creating and maintaining a tap. External commands should be added to a `cmd` directory in the tap. An external command `extcmd` implemented as a Ruby command should live in `cmd/extcmd.rb` (don't forget to `chmod +x`). @@ -109,7 +109,7 @@ module Homebrew end ``` -Using the above will generate the appropriate help text: +Using the above will generate appropriate help text: ```console $ brew foo --help @@ -127,7 +127,7 @@ Do something. Place a description here. -h, --help Show this message. ``` -Use the `named_args` method to specify the type and number of named arguments that are expected. Pass a symbol to indicate the type of argument expected. Pass an array of symbols to indicate that multiple types should be expected. Pass an array of strings to specify the specific options that should be expected (see the [`brew analytics`](https://github.com/Homebrew/brew/blob/HEAD/Library/Homebrew/cmd/analytics.rb) command for an example of this). +Use the `named_args` method to specify the type and number of named arguments that are expected. Pass either a symbol to indicate the type of argument expected, an array of symbols to indicate that multiple types should be expected, or an array of strings to specify which specific options should be expected (see the [`brew analytics`](https://github.com/Homebrew/brew/blob/HEAD/Library/Homebrew/cmd/analytics.rb) command for an example of this). Pass an integer to the `number`, `min`, or `max` parameter of `named_args` to specify the number of named arguments that are expected. See the following examples:
false
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/bottle.rb
@@ -50,7 +50,7 @@ module Homebrew def bottle_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `bottle` [<options>] <formula> + `bottle` [<options>] <formula> [<formula> ...] Generate a bottle (binary package) from a formula that was installed with `--build-bottle`.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/bump-unversioned-casks.rb
@@ -18,7 +18,7 @@ module Homebrew def self.bump_unversioned_casks_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `bump-unversioned-casks` [<options>] [<cask>|<tap>] + `bump-unversioned-casks` [<options>] <cask>|<tap> [<cask>|<tap> ...] Check all casks with unversioned URLs in a given <tap> for updates. EOS
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/bump.rb
@@ -12,7 +12,7 @@ module Homebrew def bump_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `bump` [<options>] [<formula>] + `bump` [<options>] [<formula>] [<formula> ...] Display out-of-date brew formulae and the latest version available. Also displays whether a pull request has been opened with the URL.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/command.rb
@@ -13,7 +13,7 @@ module Homebrew def command_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `command` <cmd> + `command` <cmd> [<cmd> ...] Display the path to the file being used when invoking `brew` <cmd>. EOS
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/edit.rb
@@ -13,7 +13,7 @@ module Homebrew def edit_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `edit` [<formula>|<cask>] + `edit` [<formula>|<cask>] [<formula>|<cask> ...] Open a <formula> or <cask> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the Homebrew repository for editing if no formula is provided.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/formula.rb
@@ -13,7 +13,7 @@ module Homebrew def formula_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `formula` <formula> + `formula` <formula> [<formula> ...] Display the path where <formula> is located. EOS
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/irb.rb
@@ -34,6 +34,8 @@ def irb_args switch "--pry", env: :pry, description: "Use Pry instead of IRB. Implied if `HOMEBREW_PRY` is set." + + named_args :none end end
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/linkage.rb
@@ -14,7 +14,7 @@ module Homebrew def linkage_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `linkage` [<options>] [<formula>] + `linkage` [<options>] [<formula>] [<formula> ...] Check the library links from the given <formula> kegs. If no <formula> are provided, check all kegs. Raises an error if run on uninstalled formulae.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/livecheck.rb
@@ -20,7 +20,7 @@ module Homebrew def livecheck_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `livecheck` [<formulae>|<casks>] + `livecheck` [<formula>|<cask>] [<formula>|<cask> ...] Check for newer versions of formulae and/or casks from upstream.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/mirror.rb
@@ -13,7 +13,7 @@ module Homebrew def mirror_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `mirror` <formula> + `mirror` <formula> [<formula> ...] Reupload the stable URL of a formula to Bintray for use as a mirror. EOS
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/pr-publish.rb
@@ -29,7 +29,7 @@ def pr_publish_args flag "--workflow=", description: "Target workflow filename (default: `publish-commit-bottles.yml`)." - named_args number: 1 + named_args min: 1 end end
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/pr-pull.rb
@@ -71,7 +71,7 @@ def pr_pull_args conflicts "--clean", "--autosquash" - named_args number: 1 + named_args min: 1 end end
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/style.rb
@@ -15,7 +15,7 @@ module Homebrew def style_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `style` [<options>] [<file>|<tap>|<formula>] + `style` [<options>] [<file>|<tap>|<formula>|<cask>] [<file>|<tap>|<formula>|<cask> ...] Check formulae or files for conformance to Homebrew style guidelines.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/test.rb
@@ -15,7 +15,7 @@ module Homebrew def test_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `test` [<options>] <formula> + `test` [<options>] <formula> [<formula> ...] Run the test method provided by an installed formula. There is no standard output or return code, but generally it should notify the
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/unbottled.rb
@@ -13,7 +13,7 @@ module Homebrew def unbottled_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `unbottled` [<formula>] + `unbottled` [<formula>] [<formula> ...] Outputs the unbottled dependents of formulae. EOS
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/unpack.rb
@@ -14,7 +14,7 @@ module Homebrew def unpack_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `unpack` [<options>] <formula> + `unpack` [<options>] <formula> [<formula ...>] Unpack the source files for <formula> into subdirectories of the current working directory.
true
Other
Homebrew
brew
cf654da251fff2d6487abaf6d4736161544a6772.json
dev-cmd: indicate multiple named args in usage banner
Library/Homebrew/dev-cmd/update-python-resources.rb
@@ -13,7 +13,7 @@ module Homebrew def update_python_resources_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `update-python-resources` [<options>] <formula> + `update-python-resources` [<options>] <formula> [<formula> ...] Update versions for PyPI resource blocks in <formula>. EOS @@ -34,7 +34,7 @@ def update_python_resources_args comma_array "--exclude-packages=", description: "Exclude these packages when finding resources." - named_args :formula, number: 1 + named_args :formula, min: 1 end end
true
Other
Homebrew
brew
332372469fd38cec8bedebaf49c1cd7fce0de4a3.json
cmd: indicate multiple named args in usage banner
Library/Homebrew/cmd/--cache.rb
@@ -16,7 +16,7 @@ module Homebrew def __cache_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `--cache` [<options>] [<formula>|<cask>] + `--cache` [<options>] [<formula>|<cask>] [<formula>|<cask> ...] Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
true
Other
Homebrew
brew
332372469fd38cec8bedebaf49c1cd7fce0de4a3.json
cmd: indicate multiple named args in usage banner
Library/Homebrew/cmd/--caskroom.rb
@@ -10,7 +10,7 @@ module Homebrew def __caskroom_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `--caskroom` [<cask>] + `--caskroom` [<cask>] [<cask> ...] Display Homebrew's Caskroom path.
true
Other
Homebrew
brew
332372469fd38cec8bedebaf49c1cd7fce0de4a3.json
cmd: indicate multiple named args in usage banner
Library/Homebrew/cmd/--cellar.rb
@@ -9,7 +9,7 @@ module Homebrew def __cellar_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `--cellar` [<formula>] + `--cellar` [<formula>] [<formula> ...] Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if that directory doesn't exist, `$(brew --repository)/Cellar`.
true
Other
Homebrew
brew
332372469fd38cec8bedebaf49c1cd7fce0de4a3.json
cmd: indicate multiple named args in usage banner
Library/Homebrew/cmd/--env.rb
@@ -15,7 +15,7 @@ module Homebrew def __env_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `--env` [<options>] [<formula>] + `--env` [<options>] [<formula>] [<formula> ...] Summarise Homebrew's build environment as a plain list.
true