From bdd35efed841eb833151082066fe72513e15f889 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:14:59 -0400 Subject: [PATCH] Git: Use system_command instead of Open3.capture3 In a past discussion, it was preferred that we use `system_command` in livecheck's `Git` strategy instead of `Open3.capture3` but it wasn't feasible at the time because we couldn't prevent `#system_command` from printing certain output. I resolved the `SystemCommand` shortcoming long ago in Homebrew/brew#10066, so this finally migrates the `Git` strategy to `system_command`. --- Library/Homebrew/livecheck/strategy/git.rb | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/git.rb b/Library/Homebrew/livecheck/strategy/git.rb index 5929460c56..054cfc922c 100644 --- a/Library/Homebrew/livecheck/strategy/git.rb +++ b/Library/Homebrew/livecheck/strategy/git.rb @@ -52,23 +52,22 @@ module Homebrew # @return [Hash] sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) } def self.tag_info(url, regex = nil) - # Open3#capture3 is used here because we need to capture stderr - # output and handle it in an appropriate manner. Alternatives like - # SystemCommand always print errors (as well as debug output) and - # don't meet the same goals. - stdout_str, stderr_str, _status = Open3.capture3( - { "GIT_TERMINAL_PROMPT" => "0" }, "git", "ls-remote", "--tags", url + stdout, stderr, _status = system_command( + "git", + args: ["ls-remote", "--tags", url], + env: { "GIT_TERMINAL_PROMPT" => "0" }, + print_stdout: false, + print_stderr: false, + debug: false, + verbose: false, ) tags_data = { tags: [] } - tags_data[:messages] = stderr_str.split("\n") if stderr_str.present? - return tags_data if stdout_str.blank? + tags_data[:messages] = stderr.split("\n") if stderr.present? + return tags_data if stdout.blank? - # Isolate tag strings by removing leading/trailing text - stdout_str.gsub!(%r{^.*\trefs/tags/}, "") - stdout_str.gsub!("^{}", "") - - tags = stdout_str.split("\n").uniq.sort + # Isolate tag strings and filter by regex + tags = stdout.gsub(%r{^.*\trefs/tags/|\^{}$}, "").split("\n").uniq.sort tags.select! { |t| t =~ regex } if regex tags_data[:tags] = tags