Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV/scm/git: only execute file #493

Merged
merged 1 commit into from
Jul 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ENV/scm/git: only execute file
Fixes #491.
  • Loading branch information
xu-cheng committed Jul 11, 2016
commit 963f8f16b80a5786a102893dfa0778b00885c9e7
16 changes: 10 additions & 6 deletions Library/ENV/scm/git
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ SELF_REAL = Pathname.new(__FILE__).realpath
F = File.basename(__FILE__).freeze
D = File.expand_path(File.dirname(__FILE__)).freeze

def executable?(file)
File.file?(file) && File.executable?(file)
end

def exec(*args)
# prevent fork-bombs
arg0 = args.first
Expand All @@ -35,33 +39,33 @@ when "git" then %W[HOMEBREW_GIT GIT]
when "svn" then %W[HOMEBREW_SVN]
else []
end.each do |key|
exec ENV[key], *ARGV if ENV[key] && File.executable?(ENV[key])
exec ENV[key], *ARGV if ENV[key] && executable?(ENV[key])
end

brew_version = File.expand_path("#{D}/../../../bin/#{F}")
exec brew_version, *ARGV if File.executable? brew_version
exec brew_version, *ARGV if executable? brew_version

`/usr/bin/which -a #{F} 2>/dev/null`.split("\n").each do |path|
exec path, *ARGV unless path == "/usr/bin/#{F}"
end

popup_stub = false
if File.executable? "/usr/bin/xcode-select"
if 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
exec path, *ARGV if File.executable? path
exec path, *ARGV if executable? path
end
end

path = "/Applications/Xcode.app/Contents/Developer/usr/bin/#{F}"
exec path, *ARGV if File.executable? path
exec path, *ARGV if executable? path

path = "/usr/bin/#{F}"
exec path, *ARGV if !popup_stub && File.executable?(path)
exec path, *ARGV if !popup_stub && executable?(path)

abort "You must: brew install #{F}"