From cf5ecfc06d0e280eff20667437770d3a21fb6dd5 Mon Sep 17 00:00:00 2001
From: Jack Nagel <jacknagel@gmail.com>
Date: Fri, 2 May 2014 09:49:11 -0500
Subject: [PATCH] doctor: suppress warnings from git wrapper script

Fixes Homebrew/homebrew#28901.
---
 Library/Homebrew/cmd/doctor.rb | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb
index 5945fa31b0..bce3ddb4f2 100644
--- a/Library/Homebrew/cmd/doctor.rb
+++ b/Library/Homebrew/cmd/doctor.rb
@@ -53,6 +53,14 @@ class Checks
   def inject_file_list(list, str)
     list.inject(str) { |s, f| s << "    #{f}\n" }
   end
+
+  # Git will always be on PATH because of the wrapper script in
+  # Library/Contributions/cmd, so we check if there is a *real*
+  # git here to avoid multiple warnings.
+  def git?
+    return @git if instance_variable_defined?(:@git)
+    @git = which("git") && quiet_system("git", "--version")
+  end
 ############# END HELPERS
 
 # Sorry for the lack of an indent here, the diff would have been unreadable.
@@ -728,7 +736,7 @@ def __check_git_version
 end
 
 def check_for_git
-  if which "git"
+  if git?
     __check_git_version
   else <<-EOS.undent
     Git could not be found in your PATH.
@@ -740,7 +748,7 @@ def check_for_git
 end
 
 def check_git_newline_settings
-  return unless which "git"
+  return unless git?
 
   autocrlf = `git config --get core.autocrlf`.chomp
 
@@ -758,7 +766,7 @@ def check_git_newline_settings
 end
 
 def check_git_origin
-  return unless which('git') && (HOMEBREW_REPOSITORY/'.git').exist?
+  return unless git? && (HOMEBREW_REPOSITORY/'.git').exist?
 
   HOMEBREW_REPOSITORY.cd do
     origin = `git config --get remote.origin.url`.strip
@@ -902,7 +910,7 @@ def check_missing_deps
 end
 
 def check_git_status
-  return unless which "git"
+  return unless git?
   HOMEBREW_REPOSITORY.cd do
     unless `git status --untracked-files=all --porcelain -- Library/Homebrew/ 2>/dev/null`.chomp.empty?
       <<-EOS.undent_________________________________________________________72
@@ -1014,7 +1022,7 @@ def check_for_pydistutils_cfg_in_home
 end
 
 def check_for_outdated_homebrew
-  return unless which 'git'
+  return unless git?
   HOMEBREW_REPOSITORY.cd do
     if File.directory? ".git"
       local = `git rev-parse -q --verify refs/remotes/origin/master`.chomp
-- 
GitLab