Skip to content

Instantly share code, notes, and snippets.

@apjanke

apjanke/git Secret

Created April 7, 2016 18:41
Show Gist options
  • Save apjanke/dccc1687f27e7b7813982cd5fba4cdf4 to your computer and use it in GitHub Desktop.
Save apjanke/dccc1687f27e7b7813982cd5fba4cdf4 to your computer and use it in GitHub Desktop.
git wrapper with system-exit and logging
#!/bin/sh
# Make sure this shim uses the same Ruby interpreter that is used by Homebrew.
unset RUBYLIB
unset RUBYOPT
if [ -z "$HOMEBREW_RUBY_PATH" ]
then
echo "${0##*/}: The build tool has reset ENV; --env=std required." >&2
exit 1
fi
exec "$HOMEBREW_RUBY_PATH" -x "$0" "$@"
#!/usr/bin/env ruby -W0
# This script because we support $GIT, $HOMEBREW_SVN, etc., Xcode-only and
# no Xcode/CLT configurations. Order is careful to be what the user would want.
F = File.basename(__FILE__).freeze
D = File.expand_path(File.dirname(__FILE__)).freeze
def logit(str)
open("/Users/brew/Library/Logs/Homebrew/scm_git.log", "a") { |f|
f.puts str
f.flush
}
end
# logit "F: #{F} D: #{D} expand_path: #{File.expand_path(__FILE__)}"
def exec2(*args)
# prevent fork-bombs
arg0 = args.first
return if arg0 =~ /^#{F}/i || File.expand_path(arg0) == File.expand_path(__FILE__)
system *args
exit $?
end
case F.downcase
when "git" then %W[HOMEBREW_GIT GIT]
when "svn" then %W[HOMEBREW_SVN]
else []
end.each do |key|
exec2 ENV[key], *ARGV if ENV[key] && File.executable?(ENV[key])
end
brew_version = File.expand_path("#{D}/../../../bin/#{F}")
exec2 brew_version, *ARGV if File.executable? brew_version
`/usr/bin/which -a #{F} 2>/dev/null`.split("\n").each do |path|
exec2 path, *ARGV unless path == "/usr/bin/#{F}"
end
popup_stub = false
if File.executable? "/usr/bin/xcode-select"
# xcode-select will return empty on no Xcode/CLT configuration.
# /usr/bin/<tool> will be a popup stub under such configuration.
# xcrun hangs if xcode-select is set to "/"
path = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
popup_stub = path.empty?
if !popup_stub && path != "/"
path = `/usr/bin/xcrun -find #{F} 2>/dev/null`.chomp
exec2 path, *ARGV if File.executable? path
end
end
path = "/Applications/Xcode.app/Contents/Developer/usr/bin/#{F}"
exec2 path, *ARGV if File.executable? path
path = "/usr/bin/#{F}"
exec2 path, *ARGV if !popup_stub && File.executable?(path)
abort "You must: brew install #{F}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment