mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #13387 from samford/livecheck/git-use-system_command
Git: Use system_command instead of Open3.capture3
This commit is contained in:
commit
a909be581b
@ -52,23 +52,22 @@ module Homebrew
|
|||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
def self.tag_info(url, regex = nil)
|
def self.tag_info(url, regex = nil)
|
||||||
# Open3#capture3 is used here because we need to capture stderr
|
stdout, stderr, _status = system_command(
|
||||||
# output and handle it in an appropriate manner. Alternatives like
|
"git",
|
||||||
# SystemCommand always print errors (as well as debug output) and
|
args: ["ls-remote", "--tags", url],
|
||||||
# don't meet the same goals.
|
env: { "GIT_TERMINAL_PROMPT" => "0" },
|
||||||
stdout_str, stderr_str, _status = Open3.capture3(
|
print_stdout: false,
|
||||||
{ "GIT_TERMINAL_PROMPT" => "0" }, "git", "ls-remote", "--tags", url
|
print_stderr: false,
|
||||||
|
debug: false,
|
||||||
|
verbose: false,
|
||||||
)
|
)
|
||||||
|
|
||||||
tags_data = { tags: [] }
|
tags_data = { tags: [] }
|
||||||
tags_data[:messages] = stderr_str.split("\n") if stderr_str.present?
|
tags_data[:messages] = stderr.split("\n") if stderr.present?
|
||||||
return tags_data if stdout_str.blank?
|
return tags_data if stdout.blank?
|
||||||
|
|
||||||
# Isolate tag strings by removing leading/trailing text
|
# Isolate tag strings and filter by regex
|
||||||
stdout_str.gsub!(%r{^.*\trefs/tags/}, "")
|
tags = stdout.gsub(%r{^.*\trefs/tags/|\^{}$}, "").split("\n").uniq.sort
|
||||||
stdout_str.gsub!("^{}", "")
|
|
||||||
|
|
||||||
tags = stdout_str.split("\n").uniq.sort
|
|
||||||
tags.select! { |t| t =~ regex } if regex
|
tags.select! { |t| t =~ regex } if regex
|
||||||
tags_data[:tags] = tags
|
tags_data[:tags] = tags
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user