Merge pull request #15104 from dduugg/enable-io-types

Enable IO and UpdateTest types
This commit is contained in:
Mike McQuaid 2023-03-31 09:12:25 +01:00 committed by GitHub
commit 0d17bbbec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 22 deletions

View File

@ -1,14 +1,12 @@
# typed: false # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
extend T::Sig extend T::Sig
module_function
sig { returns(CLI::Parser) } sig { returns(CLI::Parser) }
def update_test_args def self.update_test_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
Run a test of `brew update` with a new repository clone. Run a test of `brew update` with a new repository clone.
@ -27,7 +25,7 @@ module Homebrew
end end
end end
def update_test def self.update_test
args = update_test_args.parse args = update_test_args.parse
# Avoid `update-report.rb` tapping Homebrew/homebrew-core # Avoid `update-report.rb` tapping Homebrew/homebrew-core
@ -51,10 +49,12 @@ module Homebrew
"master" "master"
end end
start_commit = nil # Utils.popen_read returns a String without a block argument, but that isn't easily typed. We thus label this
# as untyped for now.
start_commit = T.let("", T.untyped)
end_commit = "HEAD" end_commit = "HEAD"
cd HOMEBREW_REPOSITORY do cd HOMEBREW_REPOSITORY do
start_commit = if (commit = args.commit) start_commit = if (commit = T.let(args.commit, T.nilable(String)))
commit commit
elsif (date = args.before) elsif (date = args.before)
Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp
@ -78,7 +78,7 @@ module Homebrew
start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp
odie "Could not find start commit!" if start_commit.empty? odie "Could not find start commit!" if start_commit.empty?
end_commit = Utils.popen_read("git", "rev-parse", end_commit).chomp end_commit = T.cast(Utils.popen_read("git", "rev-parse", end_commit).chomp, String)
odie "Could not find end commit!" if end_commit.empty? odie "Could not find end commit!" if end_commit.empty?
if Utils.popen_read("git", "branch", "--list", "master").blank? if Utils.popen_read("git", "branch", "--list", "master").blank?
@ -114,7 +114,7 @@ module Homebrew
safe_system "git", "reset", "--hard", start_commit safe_system "git", "reset", "--hard", start_commit
# update ENV["PATH"] # update ENV["PATH"]
ENV["PATH"] = PATH.new(ENV.fetch("PATH")).prepend(curdir/"bin") ENV["PATH"] = PATH.new(ENV.fetch("PATH")).prepend(curdir/"bin").to_s
# run brew help to install portable-ruby (if needed) # run brew help to install portable-ruby (if needed)
quiet_system "brew", "help" quiet_system "brew", "help"
@ -139,7 +139,7 @@ module Homebrew
FileUtils.rm_rf "update-test" unless args.keep_tmp? FileUtils.rm_rf "update-test" unless args.keep_tmp?
end end
def git_tags def self.git_tags
tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
if tags.blank? if tags.blank?
tags = if (HOMEBREW_REPOSITORY/".git/shallow").exist? tags = if (HOMEBREW_REPOSITORY/".git/shallow").exist?

View File

@ -117,6 +117,6 @@ module GitRepositoryExtension
raise "Git is unavailable" raise "Git is unavailable"
end end
T.unsafe(Utils).popen_read(Utils::Git.git, *args, safe: safe, chdir: self, err: err).chomp.presence Utils.popen_read(Utils::Git.git, *args, safe: safe, chdir: self, err: err).chomp.presence
end end
end end

View File

@ -1,4 +1,4 @@
# typed: false # typed: true
# frozen_string_literal: true # frozen_string_literal: true
class IO class IO
@ -6,17 +6,19 @@ class IO
line = +"" line = +""
buffer = +"" buffer = +""
loop do begin
break if buffer == sep loop do
break if buffer == sep
read_nonblock(1, buffer) read_nonblock(1, buffer)
line.concat(buffer) line.concat(buffer)
end
line.freeze
rescue IO::WaitReadable, EOFError
raise if line.empty?
line.freeze
end end
line.freeze
rescue IO::WaitReadable, EOFError => e
raise e if line.empty?
line.freeze
end end
end end