diff --git a/Library/Homebrew/cmd/analytics.rb b/Library/Homebrew/cmd/analytics.rb index da69de03b3..60ebb03da9 100644 --- a/Library/Homebrew/cmd/analytics.rb +++ b/Library/Homebrew/cmd/analytics.rb @@ -18,17 +18,17 @@ module Homebrew case ARGV.named.first when nil, "state" - analyticsdisabled = \ - Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chuzzle - uuid = \ - Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chuzzle + analyticsdisabled = + Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chomp + uuid = + Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chomp if ENV["HOMEBREW_NO_ANALYTICS"] puts "Analytics is disabled (by HOMEBREW_NO_ANALYTICS)." elsif analyticsdisabled == "true" puts "Analytics is disabled." else puts "Analytics is enabled." - puts "UUID: #{uuid}" if uuid + puts "UUID: #{uuid}" if uuid.present? end when "on" safe_system "git", "config", "--file=#{config_file}", diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index e71356d0e3..36f64cb62e 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -22,14 +22,14 @@ module Homebrew def update_report HOMEBREW_REPOSITORY.cd do analytics_message_displayed = - Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsmessage").chuzzle + Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsmessage").chomp == "true" cask_analytics_message_displayed = - Utils.popen_read("git", "config", "--local", "--get", "homebrew.caskanalyticsmessage").chuzzle + Utils.popen_read("git", "config", "--local", "--get", "homebrew.caskanalyticsmessage").chomp == "true" analytics_disabled = - Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsdisabled").chuzzle - if analytics_message_displayed != "true" && - cask_analytics_message_displayed != "true" && - analytics_disabled != "true" && + Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsdisabled").chomp == "true" + if !analytics_message_displayed && + !cask_analytics_message_displayed && + !analytics_disabled && !ENV["HOMEBREW_NO_ANALYTICS"] && !ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] @@ -53,8 +53,8 @@ module Homebrew end donation_message_displayed = - Utils.popen_read("git", "config", "--local", "--get", "homebrew.donationmessage").chuzzle - if donation_message_displayed != "true" + Utils.popen_read("git", "config", "--local", "--get", "homebrew.donationmessage").chomp == "true" + unless donation_message_displayed ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:" puts " #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n" diff --git a/Library/Homebrew/extend/git_repository.rb b/Library/Homebrew/extend/git_repository.rb index 9bfb6cf43c..8cd389ddf2 100644 --- a/Library/Homebrew/extend/git_repository.rb +++ b/Library/Homebrew/extend/git_repository.rb @@ -9,7 +9,7 @@ module GitRepositoryExtension def git_origin return unless git? && Utils.git_available? - Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chuzzle + Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chomp.presence end def git_origin=(origin) @@ -21,30 +21,30 @@ module GitRepositoryExtension def git_head return unless git? && Utils.git_available? - Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chuzzle + Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chomp.presence end def git_short_head return unless git? && Utils.git_available? - Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chuzzle + Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chomp.presence end def git_last_commit return unless git? && Utils.git_available? - Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chuzzle + Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chomp.presence end def git_branch return unless git? && Utils.git_available? - Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chuzzle + Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chomp.presence end def git_last_commit_date return unless git? && Utils.git_available? - Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chuzzle + Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chomp.presence end end diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index e7777c8281..64be4d5620 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -1,10 +1,12 @@ # Contains backports from newer versions of Ruby require "backports/2.4.0/string/match" require "backports/2.5.0/string/delete_prefix" +require "active_support/core_ext/object/blank" class String # String.chomp, but if result is empty: returns nil instead. # Allows `chuzzle || foo` short-circuits. + # TODO: Deprecate. def chuzzle s = chomp s unless s.empty? @@ -12,6 +14,7 @@ class String end class NilClass + # TODO: Deprecate. def chuzzle; end end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 70a35efc27..0057791b19 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -7,6 +7,7 @@ require "pp" require_relative "load_path" +require "active_support/core_ext/object/blank" require "active_support/core_ext/numeric/time" require "active_support/core_ext/array/access" require "active_support/i18n" diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 44d4c36e4b..46160175e5 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -722,7 +722,7 @@ class TapConfig return unless Utils.git_available? tap.path.cd do - Utils.popen_read("git", "config", "--local", "--get", "homebrew.#{key}").chuzzle + Utils.popen_read("git", "config", "--local", "--get", "homebrew.#{key}").chomp.presence end end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 5238c8ccca..e0bb176fed 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -36,7 +36,7 @@ module Utils @git_path ||= Utils.popen_read( HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path" - ).chuzzle + ).chomp.presence end def self.git_version